clear
clear all
import excel "2META_DATA.xlsx", sheet("Sheet1") firstrow


rename tstatistic tstat
rename degreesoffreedom df

//original pcc
gen pcc = tstat /sqrt( tstat^2 + df )
gen       varR = (1-pcc^2)/df
gen       seR = sqrt(varR)

//winsor2 t-stat, df & pcc
winsor2 tstat df, suffix(_win1) cuts(1.5 98.5) label
gen pcc_win1 = tstat_win1 /sqrt( tstat_win1^2 + df_win1 )
gen       varR_win1 = (1-pcc_win1^2)/df_win1
gen       seR_win1 = sqrt(varR_win1)
gen       altseR_win1 = (1-pcc_win1^2)/sqrt(df_win1)
gen       pcc_prec_win1=1/seR_win1
gen       altpcc_prec_win1=1/altseR_win1

*Inverse of estimates per study
bysort id: egen perstudy = count(tstat_win1)
gen        invperstudy = 1/perstudy

*Generate Instrum_win1ental variable
gen        Instrum_win1=1/sqrt(df_win1) // The Instrum_win1ent for the standard error (SE) of the PCC

gen violence = 0
replace violence=1 if civil_war==1 | distortions_assasinations_confli==1

gen residual_div=0
replace residual_div=1 if cultural_div==1 | residualcategory_div==1

gen other_est_3 =0
replace other_est_3=1 if randomeffects==1 | gmm ==1 | other_est==1

gen single=0
replace single=1 if numcountries==1

gen logcitations = log(1+ googlecitations)
gen econ_journal = 1 - non_economics_journal

gen logyears = log(1 + numyear)

quietly: summarize yearofpublication
local average_year = r(mean)
gen pub_year = yearofpublication - `average_year'

sum ethnic_div linguistic_div religious_div cultural_div genetic_div birthplace_div residualcategory_div

xtset id2 // Setting the data set


****Appendix: Table A1 Summary statistics for t-values, df and PCCs*****
sum df df_win1
sum df df_win1, d

sum tstat tstat_win1
sum tstat tstat_win1, d

sum pcc pcc_win1
sum pcc pcc_win1, d 



****Table 2*****

//pcc Unweighted - all
sum pcc_win1 , d
//pcc Weighted - all 
mean pcc_win1 [aweight=(1/seR_win1)]

//pcc Unweighted - ethnic_div
sum pcc_win1 if ethnic_div==1, d
//pcc Weighted - ethnic_div
mean pcc_win1 [aweight=(1/seR_win1)] if ethnic_div==1

//pcc Unweighted - linguistic_div
 sum pcc_win1 if linguistic_div==1, d
//pcc Weighted - linguistic_div
mean pcc_win1 [aweight=(1/seR_win1)] if linguistic_div==1

//pcc Unweighted - religious_div
 sum pcc_win1 if religious_div==1, d
//pcc Weighted - religious_div
mean pcc_win1 [aweight=(1/seR_win1)] if religious_div==1

//pcc Unweighted - genetic_div
  sum pcc_win1 if genetic_div==1, d
//pcc Weighted - genetic_div
mean pcc_win1 [aweight=(1/seR_win1)] if genetic_div==1

//pcc Unweighted - birthplace_div
 sum pcc_win1 if birthplace_div==1, d
//pcc Weighted - birthplace_div
mean pcc_win1 [aweight=(1/seR_win1)] if birthplace_div==1

//pcc Unweighted - residual
 sum pcc_win1 if  cultural_div==1 | residualcategory_div==1, d
//pcc Weighted - residual 
mean pcc_win1 [aweight=(1/seR_win1)] if  cultural_div==1 | residualcategory_div==1


******Figure 1*******
scatter pcc_prec_win1 pcc_win1, xtitle("Partial correlation") ytitle("Precision (1/se)") xlabel(-1(0.5)1) ylabel(0(20)60) mcolor(gs5) graphregion(color(white))  xline(0, lp(dash) lcolor(red))


******Figure 2*******
//graph by category color
gen ethnic_category = .

replace ethnic_category=1 if ethnic_div==1
replace ethnic_category=2 if linguistic_div==1
replace ethnic_category=3 if religious_div==1
replace ethnic_category=4 if genetic_div==1
replace ethnic_category=5 if birthplace_div==1
replace ethnic_category=6 if cultural_div==1 | residualcategory_div==1

//multi graphs 
quie sum pcc_win1 if ethnic_category==1, detail
local m1 = r(mean)
local median1 = r(p50)
scatter pcc_prec_win1 pcc_win1 if ethnic_category==1, xtitle("Partial correlation") ytitle("Precision (1/se)") xlabel(-1(0.5)1) ylabel(0(20)60) mcolor(midblue) graphregion(color(white)) bgcolor(white) title("Ethnic diversity") xline(`m1', lp(solid) lcolor(gs0)) xline(`median1', lp(dash) lcolor(gs0)) name(g1)

quie sum pcc_win1 if ethnic_category==2, detail
local m2 = r(mean)
local median2 = r(p50)
scatter pcc_prec_win1 pcc_win1 if ethnic_category==2, xtitle("Partial correlation") ytitle("Precision (1/se)") xlabel(-1(0.5)1) ylabel(0(20)60) mcolor(orange) graphregion(color(white)) bgcolor(white) title("Linguistic diversity") xline(`m2', lp(solid) lcolor(gs0)) xline(`median2', lp(dash) lcolor(gs0)) name(g2)

quie sum pcc_win1 if ethnic_category==3, detail
local m3 = r(mean)
local median3 = r(p50)
scatter pcc_prec_win1 pcc_win1 if ethnic_category==3, xtitle("Partial correlation") ytitle("Precision (1/se)") xlabel(-1(0.5)1) ylabel(0(20)60) mcolor(midgreen) graphregion(color(white)) bgcolor(white) title("Religious diversity") xline(`m3', lp(solid) lcolor(gs0)) xline(`median3', lp(dash) lcolor(gs0)) name(g3)

quie sum pcc_win1 if ethnic_category==4, detail
local m4 = r(mean)
local median4 = r(p50)
scatter pcc_prec_win1 pcc_win1 if ethnic_category==4, xtitle("Partial correlation") ytitle("Precision (1/se)") xlabel(-1(0.5)1) ylabel(0(20)60) mcolor(cranberry) graphregion(color(white)) bgcolor(white) title("Genetic diversity") xline(`m4', lp(solid) lcolor(gs0)) xline(`median4', lp(dash) lcolor(gs0)) name(g4)

quie sum pcc_win1 if ethnic_category==5, detail
local m5 = r(mean)
local median5 = r(p50)
scatter pcc_prec_win1 pcc_win1 if ethnic_category==5, xtitle("Partial correlation") ytitle("Precision (1/se)") xlabel(-1(0.5)1) ylabel(0(20)60) mcolor(purple) graphregion(color(white)) bgcolor(white) title("Birthplace diversity") xline(`m5', lp(solid) lcolor(gs0)) xline(`median5', lp(dash) lcolor(gs0)) name(g5)

quie sum pcc_win1 if ethnic_category==6, detail
local m6 = r(mean)
local median6 = r(p50)
scatter pcc_prec_win1 pcc_win1 if ethnic_category==6, xtitle("Partial correlation") ytitle("Precision (1/se)") xlabel(-1(0.5)1) ylabel(0(20)60) mcolor(sienna) graphregion(color(white)) bgcolor(white) title("Residual category") xline(`m6', lp(solid) lcolor(gs0)) xline(`median6', lp(dash) lcolor(gs0)) name(g6)

graph combine g1 g2 g3 g4 g5 g6 , cols(2) ycommon  iscale(0.5) graphregion(color(white))


******Table 2******
//all estimates
//FAT-PET
ivreg2 pcc_win1 seR_win1 , cl(id) // OLS
*SAVE CIs FROM BOOTEST
boottest {seR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 Instrum_win1 , cl(id) // Proxy
*SAVE CIs FROM BOOTEST
boottest {Instrum_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
 xtreg pcc_win1 seR_win1 , be // BE
 esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 pcc_win1 seR_win1 [pweight=(1/seR_win1)] , cl(id) // WLS precision
*SAVE CIs FROM BOOTEST
boottest {seR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 seR_win1 [pweight=(invperstudy)] , cl(id) // WLS study
*SAVE CIs FROM BOOTEST
boottest {seR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)



//ethnic_div
//FAT-PET
ivreg2 pcc_win1 seR_win1 if ethnic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 Instrum_win1 if ethnic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {Instrum_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
  xtreg pcc_win1 seR_win1 if ethnic_div==1, be // BE
 esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 pcc_win1 seR_win1 [pweight=(1/seR_win1)] if ethnic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 seR_win1 [pweight=(invperstudy)] if ethnic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)

//linguistic_div
//FAT-PET
ivreg2 pcc_win1 seR_win1 if linguistic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 Instrum_win1 if linguistic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {Instrum_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
xtreg pcc_win1 seR_win1 if linguistic_div==1, be // BE
esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 pcc_win1 seR_win1 [pweight=(1/seR_win1)] if linguistic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 seR_win1 [pweight=(invperstudy)] if linguistic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)

//religious_div
//FAT-PET
ivreg2 pcc_win1 seR_win1 if religious_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 Instrum_win1 if religious_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {Instrum_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
xtreg pcc_win1 seR_win1 if religious_div==1, be // BE
esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 pcc_win1 seR_win1 [pweight=(1/seR_win1)] if religious_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 seR_win1 [pweight=(invperstudy)] if religious_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)

//genetic_div
//FAT-PET
ivreg2 pcc_win1 seR_win1 if genetic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR_win1} {_cons}, nograph weight(webb)
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 Instrum_win1 if genetic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {Instrum_win1} {_cons}, nograph weight(webb)
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
xtreg pcc_win1 seR_win1 if genetic_div==1, be // BE
esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 pcc_win1 seR_win1 [pweight=(1/seR_win1)] if genetic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR_win1} {_cons}, nograph weight(webb)
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 seR_win1 [pweight=(invperstudy)] if genetic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR_win1} {_cons}, nograph weight(webb)
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)


//birthplace_div
//FAT-PET
ivreg2 pcc_win1 seR_win1 if birthplace_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR_win1} {_cons}, nograph weight(webb)
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 Instrum_win1 if birthplace_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {Instrum_win1} {_cons}, nograph weight(webb)
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
xtreg pcc_win1 seR_win1 if birthplace_div==1, be // BE
esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 pcc_win1 seR_win1 [pweight=(1/seR_win1)] if birthplace_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR_win1} {_cons}, nograph weight(webb)
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 seR_win1 [pweight=(invperstudy)] if birthplace_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR_win1} {_cons}, nograph weight(webb)
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)


//residual category
//FAT-PET
ivreg2 pcc_win1 seR_win1 if cultural_div==1 | residualcategory_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 Instrum_win1 if cultural_div==1 | residualcategory_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {Instrum_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
xtreg pcc_win1 seR_win1 if cultural_div==1 | residualcategory_div==1, be // BE
esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 pcc_win1 seR_win1 [pweight=(1/seR_win1)] if cultural_div==1 | residualcategory_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 seR_win1 [pweight=(invperstudy)] if cultural_div==1 | residualcategory_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)

 

******Table 3 Nonlinear tests: Bias-corrected effect of diversity on economic growth******
//all estimates
preserve


*Top10
quietly{
summarize pcc_prec_win1, detail
local top10bound = r(p90)
summarize pcc_win1 if pcc_prec_win1 > `top10bound'
summarize pcc_prec_win1, detail
local top10bound = r(p90)
}
reg pcc_win1 if pcc_prec_win1 > `top10bound'

***WAAP_1 = the WAAP estimator does not identify any study that would have sufficient power.
*quietly{
*gen ts = pcc_win1/seR_win1
*summarize pcc_win1 [aweight=1/(seR_win1^2)] 
*gen waapbound = abs(r(mean))/2.8
*}
*reg ts pcc_prec_win1 if seR_win1 < waapbound, noconstant
*
//Kinked model (Bom and Rachinger, 2019)
//Code (for stata) available at: https://sites.google.com/site/heikorachinger/codes 
*EK Estimator
quietly {

gen bs=pcc_win1
gen sebs=seR_win1


gen ones=1
   
sum
local M=r(N)
sum sebs
local sebs_min=r(min)
local sebs_max=r(max)
  
gen sebs2=sebs^2
gen wis=ones/sebs2
gen bs_sebs=bs/sebs
gen ones_sebs=ones/sebs

gen bswis=bs*wis
sum wis
local wis_sum=r(sum)


* FAT-PET
regress bs_sebs ones_sebs ones,noc
local pet=_b[ones_sebs]
local t1_linreg = (_b[ones_sebs]/_se[ones_sebs])
local b_lin=_b[ones_sebs]
local Q1_lin = e(rss)
di `t1_linreg'
local abs_t1_linreg = abs(`t1_linreg')
di `abs_t1_linreg'


* PEESE
regress bs_sebs ones_sebs sebs,noc
local peese=_b[ones_sebs]
local b_sq=_b[ones_sebs]
local Q1_sq = e(rss)
di `Q1_sq'
 

* FAT-PET-PEESE

if `abs_t1_linreg' > invt(`M-2', 0.975) {
    local combreg=`b_sq'
	local Q1=`Q1_sq'
	}
else {
    local combreg=`b_lin'
	local Q1=`Q1_lin'
}

* estimation of random effects variance component
local sigh2hat=max(0,`M'*((`Q1'/(`M'-e(df_m)-1))-1)/`wis_sum') 
local sighhat=sqrt(`sigh2hat') 


* Cutoff value for EK
if `combreg'>1.96*`sighhat' {
    local a1=(`combreg'-1.96*`sighhat')*(`combreg'+1.96*`sighhat')/(2*1.96*`combreg')
}
else {
	local a1=0
	}
    
	
	rename bs bs_original
	rename bs_sebs bs
	rename ones_sebs constant
	rename ones pub_bias
	
	
    noisily: display "EK regression: "

if `a1'>`sebs_min' & `a1'<`sebs_max' {
    gen sebs_a1=sebs-`a1' if sebs>`a1'
	replace sebs_a1=0 if sebs<=`a1'
	gen pubbias=sebs_a1/sebs
	noisily regress bs constant pubbias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pubbias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pubbias]
}
else if `a1'<`sebs_min' {
    noisily regress bs constant pub_bias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pub_bias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pub_bias]
}
else if `a1'>`sebs_max' {
    noisily regress bs constant, noc
	local b0_ek=_b[constant]
	local sd0_ek=_se[constant]	
}
noisily: display "EK's mean effect estimate (alpha1) and standard error:"
noisily: di `b0_ek' 
noisily: di `sd0_ek' 
noisily: display "EK's publication bias estimate (delta) and standard error:"
noisily: di `b1_ek' 
noisily: di `sd1_ek' 

}
*AK - SELECTION
*https://maxkasy.github.io/home/metastudy/
* -> Visit https://maxkasy.github.io/home/metastudy/ and upload AK_all.csv
// Use the following Model parameters:
/*
AK_Selection_model_parameters
Model for the distribution of effects
Student-t

Symmetric p(.) [CHECKED]

Cutoffs for p(.)
1.96

--Output--
estimate
standard error
*/

*Stem: https://github.com/Chishio318/stem-based_method
*in R: 

/*
Open & run R file: ste_all.R using ste_all.xlsx

--Output--
estimate
0.1005235   0.08475539
*/

restore



//ethnic_div
preserve
keep if ethnic_div==1

*Top10
quietly{
summarize pcc_prec_win1, detail
local top10bound = r(p90)
summarize pcc_win1 if pcc_prec_win1 > `top10bound'
summarize pcc_prec_win1, detail
local top10bound = r(p90)
}
reg pcc_win1 if pcc_prec_win1 > `top10bound'

***WAAP_1 = the WAAP estimator does not identify any study that would have sufficient power.
*quietly{
*gen ts = pcc_win1/seR_win1
*summarize pcc_win1 [aweight=1/(seR_win1^2)] 
*gen waapbound = abs(r(mean))/2.8
*}
*reg ts pcc_prec_win1 if seR_win1 < waapbound, noconstant

//Kinked model (Bom and Rachinger, 2019)
//Code (for stata) available at: https://sites.google.com/site/heikorachinger/codes 
*EK Estimator
quietly {

gen bs=pcc_win1
gen sebs=seR_win1


gen ones=1
   
sum
local M=r(N)
sum sebs
local sebs_min=r(min)
local sebs_max=r(max)
  
gen sebs2=sebs^2
gen wis=ones/sebs2
gen bs_sebs=bs/sebs
gen ones_sebs=ones/sebs

gen bswis=bs*wis
sum wis
local wis_sum=r(sum)


* FAT-PET
regress bs_sebs ones_sebs ones,noc
local pet=_b[ones_sebs]
local t1_linreg = (_b[ones_sebs]/_se[ones_sebs])
local b_lin=_b[ones_sebs]
local Q1_lin = e(rss)
di `t1_linreg'
local abs_t1_linreg = abs(`t1_linreg')
di `abs_t1_linreg'


* PEESE
regress bs_sebs ones_sebs sebs,noc
local peese=_b[ones_sebs]
local b_sq=_b[ones_sebs]
local Q1_sq = e(rss)
di `Q1_sq'
 

* FAT-PET-PEESE

if `abs_t1_linreg' > invt(`M-2', 0.975) {
    local combreg=`b_sq'
	local Q1=`Q1_sq'
	}
else {
    local combreg=`b_lin'
	local Q1=`Q1_lin'
}

* estimation of random effects variance component
local sigh2hat=max(0,`M'*((`Q1'/(`M'-e(df_m)-1))-1)/`wis_sum') 
local sighhat=sqrt(`sigh2hat') 


* Cutoff value for EK
if `combreg'>1.96*`sighhat' {
    local a1=(`combreg'-1.96*`sighhat')*(`combreg'+1.96*`sighhat')/(2*1.96*`combreg')
}
else {
	local a1=0
	}
    
	
	rename bs bs_original
	rename bs_sebs bs
	rename ones_sebs constant
	rename ones pub_bias
	
	
    noisily: display "EK regression: "

if `a1'>`sebs_min' & `a1'<`sebs_max' {
    gen sebs_a1=sebs-`a1' if sebs>`a1'
	replace sebs_a1=0 if sebs<=`a1'
	gen pubbias=sebs_a1/sebs
	noisily regress bs constant pubbias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pubbias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pubbias]
}
else if `a1'<`sebs_min' {
    noisily regress bs constant pub_bias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pub_bias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pub_bias]
}
else if `a1'>`sebs_max' {
    noisily regress bs constant, noc
	local b0_ek=_b[constant]
	local sd0_ek=_se[constant]	
}
noisily: display "EK's mean effect estimate (alpha1) and standard error:"
noisily: di `b0_ek' 
noisily: di `sd0_ek' 
noisily: display "EK's publication bias estimate (delta) and standard error:"
noisily: di `b1_ek' 
noisily: di `sd1_ek' 

}

*AK - SELECTION
*https://maxkasy.github.io/home/metastudy/
* -> Visit https://maxkasy.github.io/home/metastudy/ and upload AK_ethnic.csv
// Use the following Model parameters:
/*
AK_Selection_model_parameters
Model for the distribution of effects
Student-t

Symmetric p(.) [CHECKED]

Cutoffs for p(.)
1.96

--Output--
estimate
standard error
*/

*Stem: https://github.com/Chishio318/stem-based_method
*in R: 

/*
Open & run R file: ste_ethnic.R using ste_ethnic.xlsx

--Output--
estimate
0.1005234 0.09518991
*/

restore

//linguistic_div
preserve
keep if linguistic_div==1

*Top10
quietly{
summarize pcc_prec_win1, detail
local top10bound = r(p90)
summarize pcc_win1 if pcc_prec_win1 > `top10bound'
summarize pcc_prec_win1, detail
local top10bound = r(p90)
}
reg pcc_win1 if pcc_prec_win1 > `top10bound'

***WAAP_1 = the WAAP estimator does not identify any study that would have sufficient power.
*quietly{
*gen ts = pcc_win1/seR_win1
*summarize pcc_win1 [aweight=1/(seR_win1^2)] 
*gen waapbound = abs(r(mean))/2.8
*}
*reg ts pcc_prec_win1 if seR_win1 < waapbound, noconstant

//Kinked model (Bom and Rachinger, 2019)
//Code (for stata) available at: https://sites.google.com/site/heikorachinger/codes 
*EK Estimator
quietly {

gen bs=pcc_win1
gen sebs=seR_win1


gen ones=1
   
sum
local M=r(N)
sum sebs
local sebs_min=r(min)
local sebs_max=r(max)
  
gen sebs2=sebs^2
gen wis=ones/sebs2
gen bs_sebs=bs/sebs
gen ones_sebs=ones/sebs

gen bswis=bs*wis
sum wis
local wis_sum=r(sum)


* FAT-PET
regress bs_sebs ones_sebs ones,noc
local pet=_b[ones_sebs]
local t1_linreg = (_b[ones_sebs]/_se[ones_sebs])
local b_lin=_b[ones_sebs]
local Q1_lin = e(rss)
di `t1_linreg'
local abs_t1_linreg = abs(`t1_linreg')
di `abs_t1_linreg'


* PEESE
regress bs_sebs ones_sebs sebs,noc
local peese=_b[ones_sebs]
local b_sq=_b[ones_sebs]
local Q1_sq = e(rss)
di `Q1_sq'
 

* FAT-PET-PEESE

if `abs_t1_linreg' > invt(`M-2', 0.975) {
    local combreg=`b_sq'
	local Q1=`Q1_sq'
	}
else {
    local combreg=`b_lin'
	local Q1=`Q1_lin'
}

* estimation of random effects variance component
local sigh2hat=max(0,`M'*((`Q1'/(`M'-e(df_m)-1))-1)/`wis_sum') 
local sighhat=sqrt(`sigh2hat') 


* Cutoff value for EK
if `combreg'>1.96*`sighhat' {
    local a1=(`combreg'-1.96*`sighhat')*(`combreg'+1.96*`sighhat')/(2*1.96*`combreg')
}
else {
	local a1=0
	}
    
	
	rename bs bs_original
	rename bs_sebs bs
	rename ones_sebs constant
	rename ones pub_bias
	
	
    noisily: display "EK regression: "

if `a1'>`sebs_min' & `a1'<`sebs_max' {
    gen sebs_a1=sebs-`a1' if sebs>`a1'
	replace sebs_a1=0 if sebs<=`a1'
	gen pubbias=sebs_a1/sebs
	noisily regress bs constant pubbias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pubbias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pubbias]
}
else if `a1'<`sebs_min' {
    noisily regress bs constant pub_bias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pub_bias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pub_bias]
}
else if `a1'>`sebs_max' {
    noisily regress bs constant, noc
	local b0_ek=_b[constant]
	local sd0_ek=_se[constant]	
}
noisily: display "EK's mean effect estimate (alpha1) and standard error:"
noisily: di `b0_ek' 
noisily: di `sd0_ek' 
noisily: display "EK's publication bias estimate (delta) and standard error:"
noisily: di `b1_ek' 
noisily: di `sd1_ek' 

}

*AK - SELECTION
*https://maxkasy.github.io/home/metastudy/
* -> Visit https://maxkasy.github.io/home/metastudy/ and upload AK_linguistic.csv
// Use the following Model parameters:
/*
AK_Selection_model_parameters
Model for the distribution of effects
Student-t

Symmetric p(.) [CHECKED]

Cutoffs for p(.)
1.96

--Output--
estimate
standard error
*/

*Stem: https://github.com/Chishio318/stem-based_method
*in R: 

/*
Open & run R file: ste_linguistic.R using ste_linguistic.xlsx

--Output--
estimate
-0.007900781 0.0572052
*/

restore


//religious_div
preserve
keep if religious_div==1

*Top10
quietly{
summarize pcc_prec_win1, detail
local top10bound = r(p90)
summarize pcc_win1 if pcc_prec_win1 > `top10bound'
summarize pcc_prec_win1, detail
local top10bound = r(p90)
}
reg pcc_win1 if pcc_prec_win1 > `top10bound'

***WAAP_1 = the WAAP estimator does not identify any study that would have sufficient power.
*quietly{
*gen ts = pcc_win1/seR_win1
*summarize pcc_win1 [aweight=1/(seR_win1^2)] 
*gen waapbound = abs(r(mean))/2.8
*}
*reg ts pcc_prec_win1 if seR_win1 < waapbound, noconstant

//Kinked model (Bom and Rachinger, 2019)
//Code (for stata) available at: https://sites.google.com/site/heikorachinger/codes 
*EK Estimator
quietly {

gen bs=pcc_win1
gen sebs=seR_win1


gen ones=1
   
sum
local M=r(N)
sum sebs
local sebs_min=r(min)
local sebs_max=r(max)
  
gen sebs2=sebs^2
gen wis=ones/sebs2
gen bs_sebs=bs/sebs
gen ones_sebs=ones/sebs

gen bswis=bs*wis
sum wis
local wis_sum=r(sum)


* FAT-PET
regress bs_sebs ones_sebs ones,noc
local pet=_b[ones_sebs]
local t1_linreg = (_b[ones_sebs]/_se[ones_sebs])
local b_lin=_b[ones_sebs]
local Q1_lin = e(rss)
di `t1_linreg'
local abs_t1_linreg = abs(`t1_linreg')
di `abs_t1_linreg'


* PEESE
regress bs_sebs ones_sebs sebs,noc
local peese=_b[ones_sebs]
local b_sq=_b[ones_sebs]
local Q1_sq = e(rss)
di `Q1_sq'
 

* FAT-PET-PEESE

if `abs_t1_linreg' > invt(`M-2', 0.975) {
    local combreg=`b_sq'
	local Q1=`Q1_sq'
	}
else {
    local combreg=`b_lin'
	local Q1=`Q1_lin'
}

* estimation of random effects variance component
local sigh2hat=max(0,`M'*((`Q1'/(`M'-e(df_m)-1))-1)/`wis_sum') 
local sighhat=sqrt(`sigh2hat') 


* Cutoff value for EK
if `combreg'>1.96*`sighhat' {
    local a1=(`combreg'-1.96*`sighhat')*(`combreg'+1.96*`sighhat')/(2*1.96*`combreg')
}
else {
	local a1=0
	}
    
	
	rename bs bs_original
	rename bs_sebs bs
	rename ones_sebs constant
	rename ones pub_bias
	
	
    noisily: display "EK regression: "

if `a1'>`sebs_min' & `a1'<`sebs_max' {
    gen sebs_a1=sebs-`a1' if sebs>`a1'
	replace sebs_a1=0 if sebs<=`a1'
	gen pubbias=sebs_a1/sebs
	noisily regress bs constant pubbias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pubbias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pubbias]
}
else if `a1'<`sebs_min' {
    noisily regress bs constant pub_bias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pub_bias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pub_bias]
}
else if `a1'>`sebs_max' {
    noisily regress bs constant, noc
	local b0_ek=_b[constant]
	local sd0_ek=_se[constant]	
}
noisily: display "EK's mean effect estimate (alpha1) and standard error:"
noisily: di `b0_ek' 
noisily: di `sd0_ek' 
noisily: display "EK's publication bias estimate (delta) and standard error:"
noisily: di `b1_ek' 
noisily: di `sd1_ek' 

}

*AK - SELECTION
*https://maxkasy.github.io/home/metastudy/
* -> Visit https://maxkasy.github.io/home/metastudy/ and upload AK_religious.csv
// Use the following Model parameters:
/*
AK_Selection_model_parameters
Model for the distribution of effects
Student-t

Symmetric p(.) [CHECKED]

Cutoffs for p(.)
1.96

--Output--
estimate
standard error
*/

*Stem: https://github.com/Chishio318/stem-based_method
*in R: 

/*
Open & run R file: ste_religious.R using ste_religious.xlsx

--Output--
estimate
-0.05163964 0.05460189
*/

restore


//genetic_div
preserve
keep if genetic_div==1

*Top10
quietly{
summarize pcc_prec_win1, detail
local top10bound = r(p90)
summarize pcc_win1 if pcc_prec_win1 > `top10bound'
summarize pcc_prec_win1, detail
local top10bound = r(p90)
}
reg pcc_win1 if pcc_prec_win1 > `top10bound'

**WAAP_1
quietly{
gen ts = pcc_win1/seR_win1
summarize pcc_win1 [aweight=1/(seR_win1^2)] 
gen waapbound = abs(r(mean))/2.8
}
reg ts pcc_prec_win1 if seR_win1 < waapbound, noconstant

//Kinked model (Bom and Rachinger, 2019)
//Code (for stata) available at: https://sites.google.com/site/heikorachinger/codes 
*EK Estimator
quietly {

gen bs=pcc_win1
gen sebs=seR_win1


gen ones=1
   
sum
local M=r(N)
sum sebs
local sebs_min=r(min)
local sebs_max=r(max)
  
gen sebs2=sebs^2
gen wis=ones/sebs2
gen bs_sebs=bs/sebs
gen ones_sebs=ones/sebs

gen bswis=bs*wis
sum wis
local wis_sum=r(sum)


* FAT-PET
regress bs_sebs ones_sebs ones,noc
local pet=_b[ones_sebs]
local t1_linreg = (_b[ones_sebs]/_se[ones_sebs])
local b_lin=_b[ones_sebs]
local Q1_lin = e(rss)
di `t1_linreg'
local abs_t1_linreg = abs(`t1_linreg')
di `abs_t1_linreg'


* PEESE
regress bs_sebs ones_sebs sebs,noc
local peese=_b[ones_sebs]
local b_sq=_b[ones_sebs]
local Q1_sq = e(rss)
di `Q1_sq'
 

* FAT-PET-PEESE

if `abs_t1_linreg' > invt(`M-2', 0.975) {
    local combreg=`b_sq'
	local Q1=`Q1_sq'
	}
else {
    local combreg=`b_lin'
	local Q1=`Q1_lin'
}

* estimation of random effects variance component
local sigh2hat=max(0,`M'*((`Q1'/(`M'-e(df_m)-1))-1)/`wis_sum') 
local sighhat=sqrt(`sigh2hat') 


* Cutoff value for EK
if `combreg'>1.96*`sighhat' {
    local a1=(`combreg'-1.96*`sighhat')*(`combreg'+1.96*`sighhat')/(2*1.96*`combreg')
}
else {
	local a1=0
	}
    
	
	rename bs bs_original
	rename bs_sebs bs
	rename ones_sebs constant
	rename ones pub_bias
	
	
    noisily: display "EK regression: "

if `a1'>`sebs_min' & `a1'<`sebs_max' {
    gen sebs_a1=sebs-`a1' if sebs>`a1'
	replace sebs_a1=0 if sebs<=`a1'
	gen pubbias=sebs_a1/sebs
	noisily regress bs constant pubbias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pubbias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pubbias]
}
else if `a1'<`sebs_min' {
    noisily regress bs constant pub_bias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pub_bias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pub_bias]
}
else if `a1'>`sebs_max' {
    noisily regress bs constant, noc
	local b0_ek=_b[constant]
	local sd0_ek=_se[constant]	
}
noisily: display "EK's mean effect estimate (alpha1) and standard error:"
noisily: di `b0_ek' 
noisily: di `sd0_ek' 
noisily: display "EK's publication bias estimate (delta) and standard error:"
noisily: di `b1_ek' 
noisily: di `sd1_ek' 

}

*AK - SELECTION
*https://maxkasy.github.io/home/metastudy/
* -> Visit https://maxkasy.github.io/home/metastudy/ and upload AK_genetic.csv
// Use the following Model parameters:
/*
AK_Selection_model_parameters
Model for the distribution of effects
Student-t

Symmetric p(.) [CHECKED]

Cutoffs for p(.)
1.96

--Output--
estimate
standard error
*/

*Stem: https://github.com/Chishio318/stem-based_method
*in R: 

/*
Open & run R file: ste_genetic.R using ste_genetic.xlsx

--Output--
estimate
0.1505232 0.02597072
*/

restore


//birthplace_div
preserve
keep if birthplace_div==1

*Top10
quietly{
summarize pcc_prec_win1, detail
local top10bound = r(p90)
summarize pcc_win1 if pcc_prec_win1 > `top10bound'
summarize pcc_prec_win1, detail
local top10bound = r(p90)
}
reg pcc_win1 if pcc_prec_win1 > `top10bound'

**WAAP_1
quietly{
gen ts = pcc_win1/seR_win1
summarize pcc_win1 [aweight=1/(seR_win1^2)] 
gen waapbound = abs(r(mean))/2.8
}
reg ts pcc_prec_win1 if seR_win1 < waapbound, noconstant

//Kinked model (Bom and Rachinger, 2019)
//Code (for stata) available at: https://sites.google.com/site/heikorachinger/codes 
*EK Estimator
quietly {

gen bs=pcc_win1
gen sebs=seR_win1


gen ones=1
   
sum
local M=r(N)
sum sebs
local sebs_min=r(min)
local sebs_max=r(max)
  
gen sebs2=sebs^2
gen wis=ones/sebs2
gen bs_sebs=bs/sebs
gen ones_sebs=ones/sebs

gen bswis=bs*wis
sum wis
local wis_sum=r(sum)


* FAT-PET
regress bs_sebs ones_sebs ones,noc
local pet=_b[ones_sebs]
local t1_linreg = (_b[ones_sebs]/_se[ones_sebs])
local b_lin=_b[ones_sebs]
local Q1_lin = e(rss)
di `t1_linreg'
local abs_t1_linreg = abs(`t1_linreg')
di `abs_t1_linreg'


* PEESE
regress bs_sebs ones_sebs sebs,noc
local peese=_b[ones_sebs]
local b_sq=_b[ones_sebs]
local Q1_sq = e(rss)
di `Q1_sq'
 

* FAT-PET-PEESE

if `abs_t1_linreg' > invt(`M-2', 0.975) {
    local combreg=`b_sq'
	local Q1=`Q1_sq'
	}
else {
    local combreg=`b_lin'
	local Q1=`Q1_lin'
}

* estimation of random effects variance component
local sigh2hat=max(0,`M'*((`Q1'/(`M'-e(df_m)-1))-1)/`wis_sum') 
local sighhat=sqrt(`sigh2hat') 


* Cutoff value for EK
if `combreg'>1.96*`sighhat' {
    local a1=(`combreg'-1.96*`sighhat')*(`combreg'+1.96*`sighhat')/(2*1.96*`combreg')
}
else {
	local a1=0
	}
    
	
	rename bs bs_original
	rename bs_sebs bs
	rename ones_sebs constant
	rename ones pub_bias
	
	
    noisily: display "EK regression: "

if `a1'>`sebs_min' & `a1'<`sebs_max' {
    gen sebs_a1=sebs-`a1' if sebs>`a1'
	replace sebs_a1=0 if sebs<=`a1'
	gen pubbias=sebs_a1/sebs
	noisily regress bs constant pubbias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pubbias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pubbias]
}
else if `a1'<`sebs_min' {
    noisily regress bs constant pub_bias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pub_bias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pub_bias]
}
else if `a1'>`sebs_max' {
    noisily regress bs constant, noc
	local b0_ek=_b[constant]
	local sd0_ek=_se[constant]	
}
noisily: display "EK's mean effect estimate (alpha1) and standard error:"
noisily: di `b0_ek' 
noisily: di `sd0_ek' 
noisily: display "EK's publication bias estimate (delta) and standard error:"
noisily: di `b1_ek' 
noisily: di `sd1_ek' 

}

*AK - SELECTION
*https://maxkasy.github.io/home/metastudy/
* -> Visit https://maxkasy.github.io/home/metastudy/ and upload AK_birthplace.csv
// Use the following Model parameters:
/*
AK_Selection_model_parameters
Model for the distribution of effects
Student-t

Symmetric p(.) [CHECKED]

Cutoffs for p(.)
1.96

--Output--
estimate
standard error
*/

*Stem: https://github.com/Chishio318/stem-based_method
*in R: 

/*
Open & run R file: ste_birthplace.R using ste_birthplace.xlsx

--Output--
estimate
0.06368119 0.0670386
*/

restore


//residual category
preserve
keep if cultural_div==1 | residualcategory_div==1

*Top10
quietly{
summarize pcc_prec_win1, detail
local top10bound = r(p90)
summarize pcc_win1 if pcc_prec_win1 > `top10bound'
summarize pcc_prec_win1, detail
local top10bound = r(p90)
}
reg pcc_win1 if pcc_prec_win1 > `top10bound'

***WAAP_1 = the WAAP estimator does not identify any study that would have sufficient power.
*quietly{
*gen ts = pcc_win1/seR_win1
*summarize pcc_win1 [aweight=1/(seR_win1^2)] 
*gen waapbound = abs(r(mean))/2.8
*}
*reg ts pcc_prec_win1 if seR_win1 < waapbound, noconstant

//Kinked model (Bom and Rachinger, 2019)
//Code (for stata) available at: https://sites.google.com/site/heikorachinger/codes 
*EK Estimator
quietly {

gen bs=pcc_win1
gen sebs=seR_win1


gen ones=1
   
sum
local M=r(N)
sum sebs
local sebs_min=r(min)
local sebs_max=r(max)
  
gen sebs2=sebs^2
gen wis=ones/sebs2
gen bs_sebs=bs/sebs
gen ones_sebs=ones/sebs

gen bswis=bs*wis
sum wis
local wis_sum=r(sum)


* FAT-PET
regress bs_sebs ones_sebs ones,noc
local pet=_b[ones_sebs]
local t1_linreg = (_b[ones_sebs]/_se[ones_sebs])
local b_lin=_b[ones_sebs]
local Q1_lin = e(rss)
di `t1_linreg'
local abs_t1_linreg = abs(`t1_linreg')
di `abs_t1_linreg'


* PEESE
regress bs_sebs ones_sebs sebs,noc
local peese=_b[ones_sebs]
local b_sq=_b[ones_sebs]
local Q1_sq = e(rss)
di `Q1_sq'
 

* FAT-PET-PEESE

if `abs_t1_linreg' > invt(`M-2', 0.975) {
    local combreg=`b_sq'
	local Q1=`Q1_sq'
	}
else {
    local combreg=`b_lin'
	local Q1=`Q1_lin'
}

* estimation of random effects variance component
local sigh2hat=max(0,`M'*((`Q1'/(`M'-e(df_m)-1))-1)/`wis_sum') 
local sighhat=sqrt(`sigh2hat') 


* Cutoff value for EK
if `combreg'>1.96*`sighhat' {
    local a1=(`combreg'-1.96*`sighhat')*(`combreg'+1.96*`sighhat')/(2*1.96*`combreg')
}
else {
	local a1=0
	}
    
	
	rename bs bs_original
	rename bs_sebs bs
	rename ones_sebs constant
	rename ones pub_bias
	
	
    noisily: display "EK regression: "

if `a1'>`sebs_min' & `a1'<`sebs_max' {
    gen sebs_a1=sebs-`a1' if sebs>`a1'
	replace sebs_a1=0 if sebs<=`a1'
	gen pubbias=sebs_a1/sebs
	noisily regress bs constant pubbias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pubbias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pubbias]
}
else if `a1'<`sebs_min' {
    noisily regress bs constant pub_bias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pub_bias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pub_bias]
}
else if `a1'>`sebs_max' {
    noisily regress bs constant, noc
	local b0_ek=_b[constant]
	local sd0_ek=_se[constant]	
}
noisily: display "EK's mean effect estimate (alpha1) and standard error:"
noisily: di `b0_ek' 
noisily: di `sd0_ek' 
noisily: display "EK's publication bias estimate (delta) and standard error:"
noisily: di `b1_ek' 
noisily: di `sd1_ek' 

}

*AK - SELECTION
*https://maxkasy.github.io/home/metastudy/
* -> Visit https://maxkasy.github.io/home/metastudy/ and upload AK_residual.csv
// Use the following Model parameters:
/*
AK_Selection_model_parameters
Model for the distribution of effects
Student-t

Symmetric p(.) [CHECKED]

Cutoffs for p(.)
1.96

--Output--
estimate
standard error
*/

/*
Open & run R file: ste_residual.R using ste_residual.xlsx

--Output--
estimate
-0.004754482 0.1046541
*/

restore


//Appendix: PEESE
//Table A5 Tests for publication bias: PEESE

//All estimates
//precision-weighted, study-weighted & be
preserve



qui: ivreg2 pcc_win1 varR_win1 [pweight=(1/seR_win1)], cluster(id)
*SAVE CIs FROM BOOTEST
boottest {varR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)

qui: ivreg2 pcc_win1 varR_win1 [pweight=invperstudy], cluster(id)
*SAVE CIs FROM BOOTEST
boottest {varR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)

 //be
qui: xtreg pcc_win1 varR_win1 , be // BE
 esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
 
restore



//ethnic_div
//precision-weighted, study-weighted & be
preserve

keep if ethnic_div==1

qui: ivreg2 pcc_win1 varR_win1 [pweight=(1/seR_win1)], cluster(id)
*SAVE CIs FROM BOOTEST
boottest {varR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)

qui: ivreg2 pcc_win1 varR_win1 [pweight=invperstudy], cluster(id)
*SAVE CIs FROM BOOTEST
boottest {varR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)

 //be
qui: xtreg pcc_win1 varR_win1 , be // BE
 esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
 
restore



//linguistic_div
//precision-weighted, study-weighted & be
preserve

keep if linguistic_div==1

qui: ivreg2 pcc_win1 varR_win1 [pweight=(1/seR_win1)], cluster(id)
*SAVE CIs FROM BOOTEST
boottest {varR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)

qui: ivreg2 pcc_win1 varR_win1 [pweight=invperstudy], cluster(id)
*SAVE CIs FROM BOOTEST
boottest {varR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)

 //be
qui: xtreg pcc_win1 varR_win1 , be // BE
 esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
 
restore



//religious_div
//precision-weighted, study-weighted & be
preserve

keep if religious_div==1

qui: ivreg2 pcc_win1 varR_win1 [pweight=(1/seR_win1)], cluster(id)
*SAVE CIs FROM BOOTEST
boottest {varR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)

qui: ivreg2 pcc_win1 varR_win1 [pweight=invperstudy], cluster(id)
*SAVE CIs FROM BOOTEST
boottest {varR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)

 //be
qui: xtreg pcc_win1 varR_win1 , be // BE
 esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
 
restore



//genetic_div
//precision-weighted, study-weighted & be
preserve

keep if genetic_div==1

qui: ivreg2 pcc_win1 varR_win1 [pweight=(1/seR_win1)], cluster(id)
*SAVE CIs FROM BOOTEST
boottest {varR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)

qui: ivreg2 pcc_win1 varR_win1 [pweight=invperstudy], cluster(id)
*SAVE CIs FROM BOOTEST
boottest {varR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)

 //be
qui: xtreg pcc_win1 varR_win1 , be // BE
 esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
 
restore

//birthplace_div
//precision-weighted, study-weighted & be
preserve

keep if birthplace_div==1

qui: ivreg2 pcc_win1 varR_win1 [pweight=(1/seR_win1)], cluster(id)
*SAVE CIs FROM BOOTEST
boottest {varR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)

qui: ivreg2 pcc_win1 varR_win1 [pweight=invperstudy], cluster(id)
*SAVE CIs FROM BOOTEST
boottest {varR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)

 //be
qui: xtreg pcc_win1 varR_win1 , be // BE
 esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
 
restore
 


//residual category
//precision-weighted, study-weighted & be
preserve

keep if cultural_div==1 | residualcategory_div==1

qui: ivreg2 pcc_win1 varR_win1 [pweight=(1/seR_win1)], cluster(id)
*SAVE CIs FROM BOOTEST
boottest {varR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)

qui: ivreg2 pcc_win1 varR_win1 [pweight=invperstudy], cluster(id)
*SAVE CIs FROM BOOTEST
boottest {varR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)

 //be
qui: xtreg pcc_win1 varR_win1 , be // BE
 esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
 
restore
 
*******************END PEESE*********************************

**************Appendix: Table A2 Linear tests for publication bias – Fisher's z-transformed partial correlation coefficient**************************************
gen zfisher = 0.5*ln((1+pcc)/(1-pcc))
//all estimates
//FAT-PET
ivreg2 zfisher seR , cl(id) // OLS
*SAVE CIs FROM BOOTEST
boottest {seR} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 zfisher Instrum , cl(id) // Proxy
*SAVE CIs FROM BOOTEST
boottest {Instrum} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
 xtreg zfisher seR , be // BE
 esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 zfisher seR [pweight=(1/seR)] , cl(id) // WLS precision
*SAVE CIs FROM BOOTEST
boottest {seR} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 zfisher seR [pweight=(invperstudy)] , cl(id) // WLS study
*SAVE CIs FROM BOOTEST
boottest {seR} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)

//ethnic_div
//FAT-PET
ivreg2 zfisher seR if ethnic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]")  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 zfisher Instrum if ethnic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {Instrum} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]")  starl( * 0.10 ** 0.05 *** 0.010) 
  xtreg zfisher seR if ethnic_div==1, be // BE
 esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 zfisher seR [pweight=(1/seR)] if ethnic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]")  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 zfisher seR [pweight=(invperstudy)] if ethnic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]")  starl( * 0.10 ** 0.05 *** 0.010) 

//linguistic_div
//FAT-PET
ivreg2 zfisher seR if linguistic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]")  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 zfisher Instrum if linguistic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {Instrum} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]")  starl( * 0.10 ** 0.05 *** 0.010) 
xtreg zfisher seR if linguistic_div==1, be // BE
esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 zfisher seR [pweight=(1/seR)] if linguistic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]")  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 zfisher seR [pweight=(invperstudy)] if linguistic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]")  starl( * 0.10 ** 0.05 *** 0.010) 

//religious_div
//FAT-PET
ivreg2 zfisher seR if religious_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]")  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 zfisher Instrum if religious_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {Instrum} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]")  starl( * 0.10 ** 0.05 *** 0.010)
xtreg zfisher seR if religious_div==1, be // BE
esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 zfisher seR [pweight=(1/seR)] if religious_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]")  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 zfisher seR [pweight=(invperstudy)] if religious_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]")  starl( * 0.10 ** 0.05 *** 0.010) 

//genetic_div
//FAT-PET
ivreg2 zfisher seR if genetic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR} {_cons}, nograph weight(webb)
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]")  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 zfisher Instrum if genetic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {Instrum} {_cons}, nograph weight(webb)
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]")  starl( * 0.10 ** 0.05 *** 0.010)
xtreg zfisher seR if genetic_div==1, be // BE
esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 zfisher seR [pweight=(1/seR)] if genetic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR} {_cons}, nograph weight(webb)
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]")  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 zfisher seR [pweight=(invperstudy)] if genetic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR} {_cons}, nograph weight(webb)
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]")  starl( * 0.10 ** 0.05 *** 0.010) 


//birthplace_div
//FAT-PET
ivreg2 zfisher seR if birthplace_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR} {_cons}, nograph weight(webb)
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]")  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 zfisher Instrum if birthplace_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {Instrum} {_cons}, nograph weight(webb)
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]")  starl( * 0.10 ** 0.05 *** 0.010)
xtreg zfisher seR if birthplace_div==1, be // BE
esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 zfisher seR [pweight=(1/seR)] if birthplace_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR} {_cons}, nograph weight(webb)
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]")  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 zfisher seR [pweight=(invperstudy)] if birthplace_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR} {_cons}, nograph weight(webb)
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]")  starl( * 0.10 ** 0.05 *** 0.010) 


//residual category
//FAT-PET
ivreg2 zfisher seR if cultural_div==1 | residualcategory_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]")  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 zfisher Instrum if cultural_div==1 | residualcategory_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {Instrum} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]")  starl( * 0.10 ** 0.05 *** 0.010)
xtreg zfisher seR if cultural_div==1 | residualcategory_div==1, be // BE
esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 zfisher seR [pweight=(1/seR)] if cultural_div==1 | residualcategory_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]")  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 zfisher seR [pweight=(invperstudy)] if cultural_div==1 | residualcategory_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {seR} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]")  starl( * 0.10 ** 0.05 *** 0.010) 

 
**************Appendix: Table A3 Nonlinear test: Bias-corrected effect of diversity on economic growth – Fisher's z-transformed partial correlation coefficient**************************************


//all estimates
preserve
*Top10
quietly{
summarize pcc_prec, detail
local top10bound = r(p90)
summarize zfisher if pcc_prec > `top10bound'
summarize pcc_prec, detail
local top10bound = r(p90)
}
reg zfisher if pcc_prec > `top10bound'

**WAAP_1 = the WAAP estimator does not identify any study that would have sufficient power.
*quietly{
*gen ts = zfisher/seR
*summarize zfisher [aweight=1/(seR^2)] 
*gen waapbound = abs(r(mean))/2.8
*}
*reg ts pcc_prec if seR < waapbound, noconstant
*
quietly {

gen bs=zfisher
gen sebs=seR


gen ones=1
   
sum
local M=r(N)
sum sebs
local sebs_min=r(min)
local sebs_max=r(max)
  
gen sebs2=sebs^2
gen wis=ones/sebs2
gen bs_sebs=bs/sebs
gen ones_sebs=ones/sebs

gen bswis=bs*wis
sum wis
local wis_sum=r(sum)


* FAT-PET
regress bs_sebs ones_sebs ones,noc
local pet=_b[ones_sebs]
local t1_linreg = (_b[ones_sebs]/_se[ones_sebs])
local b_lin=_b[ones_sebs]
local Q1_lin = e(rss)
di `t1_linreg'
local abs_t1_linreg = abs(`t1_linreg')
di `abs_t1_linreg'


* PEESE
regress bs_sebs ones_sebs sebs,noc
local peese=_b[ones_sebs]
local b_sq=_b[ones_sebs]
local Q1_sq = e(rss)
di `Q1_sq'
 

* FAT-PET-PEESE

if `abs_t1_linreg' > invt(`M-2', 0.975) {
    local combreg=`b_sq'
	local Q1=`Q1_sq'
	}
else {
    local combreg=`b_lin'
	local Q1=`Q1_lin'
}

* estimation of random effects variance component
local sigh2hat=max(0,`M'*((`Q1'/(`M'-e(df_m)-1))-1)/`wis_sum') 
local sighhat=sqrt(`sigh2hat') 


* Cutoff value for EK
if `combreg'>1.96*`sighhat' {
    local a1=(`combreg'-1.96*`sighhat')*(`combreg'+1.96*`sighhat')/(2*1.96*`combreg')
}
else {
	local a1=0
	}
    
	
	rename bs bs_original
	rename bs_sebs bs
	rename ones_sebs constant
	rename ones pub_bias
	
	
    noisily: display "EK regression: "

if `a1'>`sebs_min' & `a1'<`sebs_max' {
    gen sebs_a1=sebs-`a1' if sebs>`a1'
	replace sebs_a1=0 if sebs<=`a1'
	gen pubbias=sebs_a1/sebs
	noisily regress bs constant pubbias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pubbias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pubbias]
}
else if `a1'<`sebs_min' {
    noisily regress bs constant pub_bias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pub_bias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pub_bias]
}
else if `a1'>`sebs_max' {
    noisily regress bs constant, noc
	local b0_ek=_b[constant]
	local sd0_ek=_se[constant]	
}
noisily: display "EK's mean effect estimate (alpha1) and standard error:"
noisily: di `b0_ek' 
noisily: di `sd0_ek' 
noisily: display "EK's publication bias estimate (delta) and standard error:"
noisily: di `b1_ek' 
noisily: di `sd1_ek' 

}

*AK - SELECTION
*https://maxkasy.github.io/home/metastudy/
* -> Visit https://maxkasy.github.io/home/metastudy/ and upload AK_all_fisher.csv
// Use the following Model parameters:
/*
AK_Selection_model_parameters
Model for the distribution of effects
Student-t

Symmetric p(.) [CHECKED]

Cutoffs for p(.)
1.96

--Output--
estimate
standard error
*/

*Stem: https://github.com/Chishio318/stem-based_method
*in R: 

/*
Open & run R file: ste_all_fisher.R using ste_all_fisher.xlsx

--Output--
estimate
0.05153562 0.005568233
*/

restore


//ethnic_div
preserve
keep if  ethnic_div==1
*Top10
summarize pcc_prec, detail
local top10bound = r(p90)
summarize zfisher if pcc_prec > `top10bound'
summarize pcc_prec, detail
local top10bound = r(p90)
reg zfisher if pcc_prec > `top10bound'

**WAAP_1 = the WAAP estimator does not identify any study that would have sufficient power.
*gen double weightSE=1/seR^2
*sum zfisher [aweight=weightSE]
*gen waapbound = abs(r(mean))/2.8
*summarize zfisher if seR < waapbound
*ivreg2 zfisher  if seR < waapbound


quietly {

gen bs=zfisher
gen sebs=seR


gen ones=1
   
sum
local M=r(N)
sum sebs
local sebs_min=r(min)
local sebs_max=r(max)
  
gen sebs2=sebs^2
gen wis=ones/sebs2
gen bs_sebs=bs/sebs
gen ones_sebs=ones/sebs

gen bswis=bs*wis
sum wis
local wis_sum=r(sum)


* FAT-PET
regress bs_sebs ones_sebs ones,noc
local pet=_b[ones_sebs]
local t1_linreg = (_b[ones_sebs]/_se[ones_sebs])
local b_lin=_b[ones_sebs]
local Q1_lin = e(rss)
di `t1_linreg'
local abs_t1_linreg = abs(`t1_linreg')
di `abs_t1_linreg'


* PEESE
regress bs_sebs ones_sebs sebs,noc
local peese=_b[ones_sebs]
local b_sq=_b[ones_sebs]
local Q1_sq = e(rss)
di `Q1_sq'
 

* FAT-PET-PEESE

if `abs_t1_linreg' > invt(`M-2', 0.975) {
    local combreg=`b_sq'
	local Q1=`Q1_sq'
	}
else {
    local combreg=`b_lin'
	local Q1=`Q1_lin'
}

* estimation of random effects variance component
local sigh2hat=max(0,`M'*((`Q1'/(`M'-e(df_m)-1))-1)/`wis_sum') 
local sighhat=sqrt(`sigh2hat') 


* Cutoff value for EK
if `combreg'>1.96*`sighhat' {
    local a1=(`combreg'-1.96*`sighhat')*(`combreg'+1.96*`sighhat')/(2*1.96*`combreg')
}
else {
	local a1=0
	}
    
	
	rename bs bs_original
	rename bs_sebs bs
	rename ones_sebs constant
	rename ones pub_bias
	
	
    noisily: display "EK regression: "

if `a1'>`sebs_min' & `a1'<`sebs_max' {
    gen sebs_a1=sebs-`a1' if sebs>`a1'
	replace sebs_a1=0 if sebs<=`a1'
	gen pubbias=sebs_a1/sebs
	noisily regress bs constant pubbias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pubbias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pubbias]
}
else if `a1'<`sebs_min' {
    noisily regress bs constant pub_bias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pub_bias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pub_bias]
}
else if `a1'>`sebs_max' {
    noisily regress bs constant, noc
	local b0_ek=_b[constant]
	local sd0_ek=_se[constant]	
}
noisily: display "EK's mean effect estimate (alpha1) and standard error:"
noisily: di `b0_ek' 
noisily: di `sd0_ek' 
noisily: display "EK's publication bias estimate (delta) and standard error:"
noisily: di `b1_ek' 
noisily: di `sd1_ek' 

}

*AK - SELECTION
*https://maxkasy.github.io/home/metastudy/
* -> Visit https://maxkasy.github.io/home/metastudy/ and upload AK_ethnic_fisher.csv
// Use the following Model parameters:
/*
AK_Selection_model_parameters
Model for the distribution of effects
Student-t

Symmetric p(.) [CHECKED]

Cutoffs for p(.)
1.96

--Output--
estimate
standard error
*/

*Stem: https://github.com/Chishio318/stem-based_method
*in R: 

/*
Open & run R file: ste_ethnic_fisher.R using ste_ethnic_fisher.xlsx

--Output--
estimate
0.04480324 0.06106693
*/

restore 


//linguistic_div
preserve
keep if  linguistic_div ==1
*Top10
summarize pcc_prec, detail
local top10bound = r(p90)
summarize zfisher if pcc_prec > `top10bound'
summarize pcc_prec, detail
local top10bound = r(p90)
reg zfisher if pcc_prec > `top10bound'

**WAAP_1 = the WAAP estimator does not identify any study that would have sufficient power.
*gen double weightSE=1/seR^2
*sum zfisher [aweight=weightSE]
*gen waapbound = abs(r(mean))/2.8
*summarize zfisher if seR < waapbound
*ivreg2 zfisher  if seR < waapbound
*

quietly {

gen bs=zfisher
gen sebs=seR


gen ones=1
   
sum
local M=r(N)
sum sebs
local sebs_min=r(min)
local sebs_max=r(max)
  
gen sebs2=sebs^2
gen wis=ones/sebs2
gen bs_sebs=bs/sebs
gen ones_sebs=ones/sebs

gen bswis=bs*wis
sum wis
local wis_sum=r(sum)


* FAT-PET
regress bs_sebs ones_sebs ones,noc
local pet=_b[ones_sebs]
local t1_linreg = (_b[ones_sebs]/_se[ones_sebs])
local b_lin=_b[ones_sebs]
local Q1_lin = e(rss)
di `t1_linreg'
local abs_t1_linreg = abs(`t1_linreg')
di `abs_t1_linreg'


* PEESE
regress bs_sebs ones_sebs sebs,noc
local peese=_b[ones_sebs]
local b_sq=_b[ones_sebs]
local Q1_sq = e(rss)
di `Q1_sq'
 

* FAT-PET-PEESE

if `abs_t1_linreg' > invt(`M-2', 0.975) {
    local combreg=`b_sq'
	local Q1=`Q1_sq'
	}
else {
    local combreg=`b_lin'
	local Q1=`Q1_lin'
}

* estimation of random effects variance component
local sigh2hat=max(0,`M'*((`Q1'/(`M'-e(df_m)-1))-1)/`wis_sum') 
local sighhat=sqrt(`sigh2hat') 


* Cutoff value for EK
if `combreg'>1.96*`sighhat' {
    local a1=(`combreg'-1.96*`sighhat')*(`combreg'+1.96*`sighhat')/(2*1.96*`combreg')
}
else {
	local a1=0
	}
    
	
	rename bs bs_original
	rename bs_sebs bs
	rename ones_sebs constant
	rename ones pub_bias
	
	
    noisily: display "EK regression: "

if `a1'>`sebs_min' & `a1'<`sebs_max' {
    gen sebs_a1=sebs-`a1' if sebs>`a1'
	replace sebs_a1=0 if sebs<=`a1'
	gen pubbias=sebs_a1/sebs
	noisily regress bs constant pubbias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pubbias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pubbias]
}
else if `a1'<`sebs_min' {
    noisily regress bs constant pub_bias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pub_bias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pub_bias]
}
else if `a1'>`sebs_max' {
    noisily regress bs constant, noc
	local b0_ek=_b[constant]
	local sd0_ek=_se[constant]	
}
noisily: display "EK's mean effect estimate (alpha1) and standard error:"
noisily: di `b0_ek' 
noisily: di `sd0_ek' 
noisily: display "EK's publication bias estimate (delta) and standard error:"
noisily: di `b1_ek' 
noisily: di `sd1_ek' 

}

*AK - SELECTION
*https://maxkasy.github.io/home/metastudy/
* -> Visit https://maxkasy.github.io/home/metastudy/ and upload AK_linguistic_fisher.csv
// Use the following Model parameters:
/*
AK_Selection_model_parameters
Model for the distribution of effects
Student-t

Symmetric p(.) [CHECKED]

Cutoffs for p(.)
1.96

--Output--
estimate
standard error
*/

*Stem: https://github.com/Chishio318/stem-based_method
*in R: 

/*
Open & run R file: ste_linguistic_fisher.R using ste_linguistic_fisher.xlsx

--Output--
estimate
-0.007916976 0.06665659
*/

restore 


//religious_div
preserve
keep if religious_div  ==1
*Top10
summarize pcc_prec, detail
local top10bound = r(p90)
summarize zfisher if pcc_prec > `top10bound'
summarize pcc_prec, detail
local top10bound = r(p90)
reg zfisher if pcc_prec > `top10bound'

***WAAP_1 = the WAAP estimator does not identify any study that would have sufficient power.
*gen double weightSE=1/seR^2
*sum zfisher [aweight=weightSE]
*gen waapbound = abs(r(mean))/2.8
*summarize zfisher if seR < waapbound
*ivreg2 zfisher  if seR < waapbound


quietly {

gen bs=zfisher
gen sebs=seR


gen ones=1
   
sum
local M=r(N)
sum sebs
local sebs_min=r(min)
local sebs_max=r(max)
  
gen sebs2=sebs^2
gen wis=ones/sebs2
gen bs_sebs=bs/sebs
gen ones_sebs=ones/sebs

gen bswis=bs*wis
sum wis
local wis_sum=r(sum)


* FAT-PET
regress bs_sebs ones_sebs ones,noc
local pet=_b[ones_sebs]
local t1_linreg = (_b[ones_sebs]/_se[ones_sebs])
local b_lin=_b[ones_sebs]
local Q1_lin = e(rss)
di `t1_linreg'
local abs_t1_linreg = abs(`t1_linreg')
di `abs_t1_linreg'


* PEESE
regress bs_sebs ones_sebs sebs,noc
local peese=_b[ones_sebs]
local b_sq=_b[ones_sebs]
local Q1_sq = e(rss)
di `Q1_sq'
 

* FAT-PET-PEESE

if `abs_t1_linreg' > invt(`M-2', 0.975) {
    local combreg=`b_sq'
	local Q1=`Q1_sq'
	}
else {
    local combreg=`b_lin'
	local Q1=`Q1_lin'
}

* estimation of random effects variance component
local sigh2hat=max(0,`M'*((`Q1'/(`M'-e(df_m)-1))-1)/`wis_sum') 
local sighhat=sqrt(`sigh2hat') 


* Cutoff value for EK
if `combreg'>1.96*`sighhat' {
    local a1=(`combreg'-1.96*`sighhat')*(`combreg'+1.96*`sighhat')/(2*1.96*`combreg')
}
else {
	local a1=0
	}
    
	
	rename bs bs_original
	rename bs_sebs bs
	rename ones_sebs constant
	rename ones pub_bias
	
	
    noisily: display "EK regression: "

if `a1'>`sebs_min' & `a1'<`sebs_max' {
    gen sebs_a1=sebs-`a1' if sebs>`a1'
	replace sebs_a1=0 if sebs<=`a1'
	gen pubbias=sebs_a1/sebs
	noisily regress bs constant pubbias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pubbias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pubbias]
}
else if `a1'<`sebs_min' {
    noisily regress bs constant pub_bias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pub_bias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pub_bias]
}
else if `a1'>`sebs_max' {
    noisily regress bs constant, noc
	local b0_ek=_b[constant]
	local sd0_ek=_se[constant]	
}
noisily: display "EK's mean effect estimate (alpha1) and standard error:"
noisily: di `b0_ek' 
noisily: di `sd0_ek' 
noisily: display "EK's publication bias estimate (delta) and standard error:"
noisily: di `b1_ek' 
noisily: di `sd1_ek' 

}

*AK - SELECTION
*https://maxkasy.github.io/home/metastudy/
* -> Visit https://maxkasy.github.io/home/metastudy/ and upload AK_religious_fisher.csv
// Use the following Model parameters:
/*
AK_Selection_model_parameters
Model for the distribution of effects
Student-t

Symmetric p(.) [CHECKED]

Cutoffs for p(.)
1.96

--Output--
estimate
standard error
*/

*Stem: https://github.com/Chishio318/stem-based_method
*in R: 

/*
Open & run R file: ste_religious_fisher.R using ste_religious_fisher.xlsx

--Output--
estimate
-0.0516865
0.05614698
*/


restore 


//genetic_div
preserve
keep if  genetic_div   ==1
*Top10
summarize pcc_prec, detail
local top10bound = r(p90)
summarize zfisher if pcc_prec > `top10bound'
summarize pcc_prec, detail
local top10bound = r(p90)
reg zfisher if pcc_prec > `top10bound'

**WAAP_1
gen double weightSE=1/seR^2
sum zfisher [aweight=weightSE]
gen waapbound = abs(r(mean))/2.8
summarize zfisher if seR < waapbound
ivreg2 zfisher  if seR < waapbound


quietly {

gen bs=zfisher
gen sebs=seR


gen ones=1
   
sum
local M=r(N)
sum sebs
local sebs_min=r(min)
local sebs_max=r(max)
  
gen sebs2=sebs^2
gen wis=ones/sebs2
gen bs_sebs=bs/sebs
gen ones_sebs=ones/sebs

gen bswis=bs*wis
sum wis
local wis_sum=r(sum)


* FAT-PET
regress bs_sebs ones_sebs ones,noc
local pet=_b[ones_sebs]
local t1_linreg = (_b[ones_sebs]/_se[ones_sebs])
local b_lin=_b[ones_sebs]
local Q1_lin = e(rss)
di `t1_linreg'
local abs_t1_linreg = abs(`t1_linreg')
di `abs_t1_linreg'


* PEESE
regress bs_sebs ones_sebs sebs,noc
local peese=_b[ones_sebs]
local b_sq=_b[ones_sebs]
local Q1_sq = e(rss)
di `Q1_sq'
 

* FAT-PET-PEESE

if `abs_t1_linreg' > invt(`M-2', 0.975) {
    local combreg=`b_sq'
	local Q1=`Q1_sq'
	}
else {
    local combreg=`b_lin'
	local Q1=`Q1_lin'
}

* estimation of random effects variance component
local sigh2hat=max(0,`M'*((`Q1'/(`M'-e(df_m)-1))-1)/`wis_sum') 
local sighhat=sqrt(`sigh2hat') 


* Cutoff value for EK
if `combreg'>1.96*`sighhat' {
    local a1=(`combreg'-1.96*`sighhat')*(`combreg'+1.96*`sighhat')/(2*1.96*`combreg')
}
else {
	local a1=0
	}
    
	
	rename bs bs_original
	rename bs_sebs bs
	rename ones_sebs constant
	rename ones pub_bias
	
	
    noisily: display "EK regression: "

if `a1'>`sebs_min' & `a1'<`sebs_max' {
    gen sebs_a1=sebs-`a1' if sebs>`a1'
	replace sebs_a1=0 if sebs<=`a1'
	gen pubbias=sebs_a1/sebs
	noisily regress bs constant pubbias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pubbias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pubbias]
}
else if `a1'<`sebs_min' {
    noisily regress bs constant pub_bias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pub_bias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pub_bias]
}
else if `a1'>`sebs_max' {
    noisily regress bs constant, noc
	local b0_ek=_b[constant]
	local sd0_ek=_se[constant]	
}
noisily: display "EK's mean effect estimate (alpha1) and standard error:"
noisily: di `b0_ek' 
noisily: di `sd0_ek' 
noisily: display "EK's publication bias estimate (delta) and standard error:"
noisily: di `b1_ek' 
noisily: di `sd1_ek' 

}

*AK - SELECTION
*https://maxkasy.github.io/home/metastudy/
* -> Visit https://maxkasy.github.io/home/metastudy/ and upload AK_genetic_fisher.csv
// Use the following Model parameters:
/*
AK_Selection_model_parameters
Model for the distribution of effects
Student-t

Symmetric p(.) [CHECKED]

Cutoffs for p(.)
1.96

--Output--
estimate
standard error
*/

*Stem: https://github.com/Chishio318/stem-based_method
*in R: 

/*
Open & run R file: ste_genetic_fisher.R using ste_genetic_fisher.xlsx

--Output--
estimate
0.205362 0.06459411
*/

restore 


//birthplace_div
preserve
keep if  birthplace_div    ==1
*Top10
summarize pcc_prec, detail
local top10bound = r(p90)
summarize zfisher if pcc_prec > `top10bound'
summarize pcc_prec, detail
local top10bound = r(p90)
reg zfisher if pcc_prec > `top10bound'

**WAAP_1
gen double weightSE=1/seR^2
sum zfisher [aweight=weightSE]
gen waapbound = abs(r(mean))/2.8
summarize zfisher if seR < waapbound
ivreg2 zfisher  if seR < waapbound


quietly {

gen bs=zfisher
gen sebs=seR


gen ones=1
   
sum
local M=r(N)
sum sebs
local sebs_min=r(min)
local sebs_max=r(max)
  
gen sebs2=sebs^2
gen wis=ones/sebs2
gen bs_sebs=bs/sebs
gen ones_sebs=ones/sebs

gen bswis=bs*wis
sum wis
local wis_sum=r(sum)


* FAT-PET
regress bs_sebs ones_sebs ones,noc
local pet=_b[ones_sebs]
local t1_linreg = (_b[ones_sebs]/_se[ones_sebs])
local b_lin=_b[ones_sebs]
local Q1_lin = e(rss)
di `t1_linreg'
local abs_t1_linreg = abs(`t1_linreg')
di `abs_t1_linreg'


* PEESE
regress bs_sebs ones_sebs sebs,noc
local peese=_b[ones_sebs]
local b_sq=_b[ones_sebs]
local Q1_sq = e(rss)
di `Q1_sq'
 

* FAT-PET-PEESE

if `abs_t1_linreg' > invt(`M-2', 0.975) {
    local combreg=`b_sq'
	local Q1=`Q1_sq'
	}
else {
    local combreg=`b_lin'
	local Q1=`Q1_lin'
}

* estimation of random effects variance component
local sigh2hat=max(0,`M'*((`Q1'/(`M'-e(df_m)-1))-1)/`wis_sum') 
local sighhat=sqrt(`sigh2hat') 


* Cutoff value for EK
if `combreg'>1.96*`sighhat' {
    local a1=(`combreg'-1.96*`sighhat')*(`combreg'+1.96*`sighhat')/(2*1.96*`combreg')
}
else {
	local a1=0
	}
    
	
	rename bs bs_original
	rename bs_sebs bs
	rename ones_sebs constant
	rename ones pub_bias
	
	
    noisily: display "EK regression: "

if `a1'>`sebs_min' & `a1'<`sebs_max' {
    gen sebs_a1=sebs-`a1' if sebs>`a1'
	replace sebs_a1=0 if sebs<=`a1'
	gen pubbias=sebs_a1/sebs
	noisily regress bs constant pubbias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pubbias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pubbias]
}
else if `a1'<`sebs_min' {
    noisily regress bs constant pub_bias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pub_bias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pub_bias]
}
else if `a1'>`sebs_max' {
    noisily regress bs constant, noc
	local b0_ek=_b[constant]
	local sd0_ek=_se[constant]	
}
noisily: display "EK's mean effect estimate (alpha1) and standard error:"
noisily: di `b0_ek' 
noisily: di `sd0_ek' 
noisily: display "EK's publication bias estimate (delta) and standard error:"
noisily: di `b1_ek' 
noisily: di `sd1_ek' 
}

*AK - SELECTION
*https://maxkasy.github.io/home/metastudy/
* -> Visit https://maxkasy.github.io/home/metastudy/ and upload AK_birthplace_fisher.csv
// Use the following Model parameters:
/*
AK_Selection_model_parameters
Model for the distribution of effects
Student-t

Symmetric p(.) [CHECKED]

Cutoffs for p(.)
1.96

--Output--
estimate
standard error
*/

*Stem: https://github.com/Chishio318/stem-based_method
*in R: 

/*
Open & run R file: ste_birthplace_fisher.R using ste_birthplace_fisher.xlsx

--Output--
estimate
0.06377325 0.07332257
*/

restore 


//cultural_div & residualcategory_div
preserve
keep if  cultural_div     ==1 | residualcategory_div==1
*Top10
summarize pcc_prec, detail
local top10bound = r(p90)
summarize zfisher if pcc_prec > `top10bound'
summarize pcc_prec, detail
local top10bound = r(p90)
reg zfisher if pcc_prec > `top10bound'

***WAAP_1 = the WAAP estimator does not identify any study that would have sufficient power.
*gen double weightSE=1/seR^2
*sum zfisher [aweight=weightSE]
*gen waapbound = abs(r(mean))/2.8
*summarize zfisher if seR < waapbound
*ivreg2 zfisher  if seR < waapbound


quietly {

gen bs=zfisher
gen sebs=seR


gen ones=1
   
sum
local M=r(N)
sum sebs
local sebs_min=r(min)
local sebs_max=r(max)
  
gen sebs2=sebs^2
gen wis=ones/sebs2
gen bs_sebs=bs/sebs
gen ones_sebs=ones/sebs

gen bswis=bs*wis
sum wis
local wis_sum=r(sum)


* FAT-PET
regress bs_sebs ones_sebs ones,noc
local pet=_b[ones_sebs]
local t1_linreg = (_b[ones_sebs]/_se[ones_sebs])
local b_lin=_b[ones_sebs]
local Q1_lin = e(rss)
di `t1_linreg'
local abs_t1_linreg = abs(`t1_linreg')
di `abs_t1_linreg'


* PEESE
regress bs_sebs ones_sebs sebs,noc
local peese=_b[ones_sebs]
local b_sq=_b[ones_sebs]
local Q1_sq = e(rss)
di `Q1_sq'
 

* FAT-PET-PEESE

if `abs_t1_linreg' > invt(`M-2', 0.975) {
    local combreg=`b_sq'
	local Q1=`Q1_sq'
	}
else {
    local combreg=`b_lin'
	local Q1=`Q1_lin'
}

* estimation of random effects variance component
local sigh2hat=max(0,`M'*((`Q1'/(`M'-e(df_m)-1))-1)/`wis_sum') 
local sighhat=sqrt(`sigh2hat') 


* Cutoff value for EK
if `combreg'>1.96*`sighhat' {
    local a1=(`combreg'-1.96*`sighhat')*(`combreg'+1.96*`sighhat')/(2*1.96*`combreg')
}
else {
	local a1=0
	}
    
	
	rename bs bs_original
	rename bs_sebs bs
	rename ones_sebs constant
	rename ones pub_bias
	
	
    noisily: display "EK regression: "

if `a1'>`sebs_min' & `a1'<`sebs_max' {
    gen sebs_a1=sebs-`a1' if sebs>`a1'
	replace sebs_a1=0 if sebs<=`a1'
	gen pubbias=sebs_a1/sebs
	noisily regress bs constant pubbias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pubbias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pubbias]
}
else if `a1'<`sebs_min' {
    noisily regress bs constant pub_bias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pub_bias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pub_bias]
}
else if `a1'>`sebs_max' {
    noisily regress bs constant, noc
	local b0_ek=_b[constant]
	local sd0_ek=_se[constant]	
}
noisily: display "EK's mean effect estimate (alpha1) and standard error:"
noisily: di `b0_ek' 
noisily: di `sd0_ek' 
noisily: display "EK's publication bias estimate (delta) and standard error:"
noisily: di `b1_ek' 
noisily: di `sd1_ek' 

}

*AK - SELECTION
*https://maxkasy.github.io/home/metastudy/
* -> Visit https://maxkasy.github.io/home/metastudy/ and upload AK_residual_fisher.csv
// Use the following Model parameters:
/*
AK_Selection_model_parameters
Model for the distribution of effects
Student-t

Symmetric p(.) [CHECKED]

Cutoffs for p(.)
1.96

--Output--
estimate
standard error
*/

*Stem: https://github.com/Chishio318/stem-based_method
*in R: 

/*
Open & run R file: ste_residual_fisher.R using ste_residual_fisher.xlsx

--Output--
estimate
-0.004763234 0.1719842
*/

restore 



//Table A4 Tests for publication bias and bias-corrected effect – Standard errors as suggested by Stanley and Doucouliagos (2023)
*****Standard errors by Stanley and Doucouliagos, 2023*****
//all estimates
//FAT-PET
ivreg2 pcc_win1 altseR_win1 , cl(id) // OLS
*SAVE CIs FROM BOOTEST
boottest {altseR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 Instrum_win1 , cl(id) // Proxy
*SAVE CIs FROM BOOTEST
boottest {Instrum_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
 xtreg pcc_win1 altseR_win1 , be // BE
 esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 pcc_win1 altseR_win1 [pweight=(1/altseR_win1)] , cl(id) // WLS precision
*SAVE CIs FROM BOOTEST
boottest {altseR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 altseR_win1 [pweight=(invperstudy)] , cl(id) // WLS study
*SAVE CIs FROM BOOTEST
boottest {altseR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)

//Bias-corrected effect of diversity on economic growth******
//all estimates
preserve


*Top10
quietly{
summarize altpcc_prec_win1, detail
local top10bound = r(p90)
summarize pcc_win1 if altpcc_prec_win1 > `top10bound'
summarize altpcc_prec_win1, detail
local top10bound = r(p90)
}
reg pcc_win1 if altpcc_prec_win1 > `top10bound'

***WAAP_1 = the WAAP estimator does not identify any study that would have sufficient power.
*quietly{
*gen ts = pcc_win1/altseR_win1
*summarize pcc_win1 [aweight=1/(altseR_win1^2)] 
*gen waapbound = abs(r(mean))/2.8
*}
*reg ts pcc_prec_win1 if altseR_win1 < waapbound, noconstant
*
//Kinked model (Bom and Rachinger, 2019)
//Code (for stata) available at: https://sites.google.com/site/heikorachinger/codes 
*EK Estimator
quietly {


rename pcc_win1 bs
rename altseR_win1 sebs



gen ones=1
   
sum
local M=r(N)
sum sebs
local sebs_min=r(min)
local sebs_max=r(max)
  
gen sebs2=sebs^2
gen wis=ones/sebs2
gen bs_sebs=bs/sebs
gen ones_sebs=ones/sebs

gen bswis=bs*wis
sum wis
local wis_sum=r(sum)


* FAT-PET
regress bs_sebs ones_sebs ones,noc
local pet=_b[ones_sebs]
local t1_linreg = (_b[ones_sebs]/_se[ones_sebs])
local b_lin=_b[ones_sebs]
local Q1_lin = e(rss)
di `t1_linreg'
local abs_t1_linreg = abs(`t1_linreg')
di `abs_t1_linreg'


* PEESE
regress bs_sebs ones_sebs sebs,noc
local peese=_b[ones_sebs]
local b_sq=_b[ones_sebs]
local Q1_sq = e(rss)
di `Q1_sq'
 

* FAT-PET-PEESE

if `abs_t1_linreg' > invt(`M-2', 0.975) {
    local combreg=`b_sq'
	local Q1=`Q1_sq'
	}
else {
    local combreg=`b_lin'
	local Q1=`Q1_lin'
}

* estimation of random effects variance component
local sigh2hat=max(0,`M'*((`Q1'/(`M'-e(df_m)-1))-1)/`wis_sum') 
local sighhat=sqrt(`sigh2hat') 


* Cutoff value for EK
if `combreg'>1.96*`sighhat' {
    local a1=(`combreg'-1.96*`sighhat')*(`combreg'+1.96*`sighhat')/(2*1.96*`combreg')
}
else {
	local a1=0
	}
    
	
	rename bs bs_original
	rename bs_sebs bs
	rename ones_sebs constant
	rename ones pub_bias
	
	
    noisily: display "EK regression: "

if `a1'>`sebs_min' & `a1'<`sebs_max' {
    gen sebs_a1=sebs-`a1' if sebs>`a1'
	replace sebs_a1=0 if sebs<=`a1'
	gen pubbias=sebs_a1/sebs
	noisily regress bs constant pubbias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pubbias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pubbias]
}
else if `a1'<`sebs_min' {
    noisily regress bs constant pub_bias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pub_bias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pub_bias]
}
else if `a1'>`sebs_max' {
    noisily regress bs constant, noc
	local b0_ek=_b[constant]
	local sd0_ek=_se[constant]	
}
noisily: display "EK's mean effect estimate (alpha1) and standard error:"
noisily: di `b0_ek' 
noisily: di `sd0_ek' 
noisily: display "EK's publication bias estimate (delta) and standard error:"
noisily: di `b1_ek' 
noisily: di `sd1_ek' 

}

*AK - SELECTION
*https://maxkasy.github.io/home/metastudy/
* -> Visit https://maxkasy.github.io/home/metastudy/ and upload AK_all_cSE.csv
// Use the following Model parameters:
/*
AK_Selection_model_parameters
Model for the distribution of effects
Student-t

Symmetric p(.) [CHECKED]

Cutoffs for p(.)
1.96

--Output--
estimate
standard error
*/

*Stem: https://github.com/Chishio318/stem-based_method
*in R: 

/*
Open & run R file: ste_all_cSE.R using ste_all_cSE.xlsx

--Output--
estimate
0.101   0.089
*/



//ethnic_div
//FAT-PET
ivreg2 pcc_win1 altseR_win1 if ethnic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {altseR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 Instrum_win1 if ethnic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {Instrum_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
  xtreg pcc_win1 altseR_win1 if ethnic_div==1, be // BE
 esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 pcc_win1 altseR_win1 [pweight=(1/altseR_win1)] if ethnic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {altseR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 altseR_win1 [pweight=(invperstudy)] if ethnic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {altseR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
 

//Bias-corrected effect of diversity on economic growth******
//ethnic_div
preserve
keep if ethnic_div==1

*Top10
quietly{
summarize altpcc_prec_win1, detail
local top10bound = r(p90)
summarize pcc_win1 if altpcc_prec_win1 > `top10bound'
summarize altpcc_prec_win1, detail
local top10bound = r(p90)
}
reg pcc_win1 if altpcc_prec_win1 > `top10bound'

**WAAP_1 = the WAAP estimator does not identify any study that would have sufficient power.
quietly{
gen ts = pcc_win1/altseR_win1
summarize pcc_win1 [aweight=1/(altseR_win1^2)] 
gen waapbound = abs(r(mean))/2.8
}
reg ts pcc_prec_win1 if altseR_win1 < waapbound, noconstant

//Kinked model (Bom and Rachinger, 2019)
//Code (for stata) available at: https://sites.google.com/site/heikorachinger/codes 
*EK Estimator
quietly {


rename pcc_win1 bs
rename altseR_win1 sebs



gen ones=1
   
sum
local M=r(N)
sum sebs
local sebs_min=r(min)
local sebs_max=r(max)
  
gen sebs2=sebs^2
gen wis=ones/sebs2
gen bs_sebs=bs/sebs
gen ones_sebs=ones/sebs

gen bswis=bs*wis
sum wis
local wis_sum=r(sum)


* FAT-PET
regress bs_sebs ones_sebs ones,noc
local pet=_b[ones_sebs]
local t1_linreg = (_b[ones_sebs]/_se[ones_sebs])
local b_lin=_b[ones_sebs]
local Q1_lin = e(rss)
di `t1_linreg'
local abs_t1_linreg = abs(`t1_linreg')
di `abs_t1_linreg'


* PEESE
regress bs_sebs ones_sebs sebs,noc
local peese=_b[ones_sebs]
local b_sq=_b[ones_sebs]
local Q1_sq = e(rss)
di `Q1_sq'
 

* FAT-PET-PEESE

if `abs_t1_linreg' > invt(`M-2', 0.975) {
    local combreg=`b_sq'
	local Q1=`Q1_sq'
	}
else {
    local combreg=`b_lin'
	local Q1=`Q1_lin'
}

* estimation of random effects variance component
local sigh2hat=max(0,`M'*((`Q1'/(`M'-e(df_m)-1))-1)/`wis_sum') 
local sighhat=sqrt(`sigh2hat') 


* Cutoff value for EK
if `combreg'>1.96*`sighhat' {
    local a1=(`combreg'-1.96*`sighhat')*(`combreg'+1.96*`sighhat')/(2*1.96*`combreg')
}
else {
	local a1=0
	}
    
	
	rename bs bs_original
	rename bs_sebs bs
	rename ones_sebs constant
	rename ones pub_bias
	
	
    noisily: display "EK regression: "

if `a1'>`sebs_min' & `a1'<`sebs_max' {
    gen sebs_a1=sebs-`a1' if sebs>`a1'
	replace sebs_a1=0 if sebs<=`a1'
	gen pubbias=sebs_a1/sebs
	noisily regress bs constant pubbias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pubbias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pubbias]
}
else if `a1'<`sebs_min' {
    noisily regress bs constant pub_bias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pub_bias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pub_bias]
}
else if `a1'>`sebs_max' {
    noisily regress bs constant, noc
	local b0_ek=_b[constant]
	local sd0_ek=_se[constant]	
}
noisily: display "EK's mean effect estimate (alpha1) and standard error:"
noisily: di `b0_ek' 
noisily: di `sd0_ek' 
noisily: display "EK's publication bias estimate (delta) and standard error:"
noisily: di `b1_ek' 
noisily: di `sd1_ek' 

}

*AK - SELECTION
*https://maxkasy.github.io/home/metastudy/
* -> Visit https://maxkasy.github.io/home/metastudy/ and upload AK_ethnic_cSE.csv
// Use the following Model parameters:
/*
AK_Selection_model_parameters
Model for the distribution of effects
Student-t

Symmetric p(.) [CHECKED]

Cutoffs for p(.)
1.96

--Output--
estimate
standard error
*/

*Stem: https://github.com/Chishio318/stem-based_method
*in R: 

/*
Open & run R file: ste_all_cSE.R using ste_ethnic_cSE.xlsx

--Output--
estimate
0.101 0.097
*/

restore

//linguistic_div
//FAT-PET
ivreg2 pcc_win1 altseR_win1 if linguistic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {altseR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 Instrum_win1 if linguistic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {Instrum_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
xtreg pcc_win1 altseR_win1 if linguistic_div==1, be // BE
esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 pcc_win1 altseR_win1 [pweight=(1/altseR_win1)] if linguistic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {altseR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 altseR_win1 [pweight=(invperstudy)] if linguistic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {altseR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)

 
 //Bias-corrected effect of diversity on economic growth******
//linguistic_div
preserve
keep if linguistic_div==1

*Top10
quietly{
summarize altpcc_prec_win1, detail
local top10bound = r(p90)
summarize pcc_win1 if altpcc_prec_win1 > `top10bound'
summarize altpcc_prec_win1, detail
local top10bound = r(p90)
}
reg pcc_win1 if altpcc_prec_win1 > `top10bound'

***WAAP_1 = the WAAP estimator does not identify any study that would have sufficient power.
*quietly{
*gen ts = pcc_win1/altseR_win1
*summarize pcc_win1 [aweight=1/(altseR_win1^2)] 
*gen waapbound = abs(r(mean))/2.8
*}
*reg ts pcc_prec_win1 if altseR_win1 < waapbound, noconstant
*
//Kinked model (Bom and Rachinger, 2019)
//Code (for stata) available at: https://sites.google.com/site/heikorachinger/codes 
*EK Estimator
quietly {


rename pcc_win1 bs
rename altseR_win1 sebs



gen ones=1
   
sum
local M=r(N)
sum sebs
local sebs_min=r(min)
local sebs_max=r(max)
  
gen sebs2=sebs^2
gen wis=ones/sebs2
gen bs_sebs=bs/sebs
gen ones_sebs=ones/sebs

gen bswis=bs*wis
sum wis
local wis_sum=r(sum)


* FAT-PET
regress bs_sebs ones_sebs ones,noc
local pet=_b[ones_sebs]
local t1_linreg = (_b[ones_sebs]/_se[ones_sebs])
local b_lin=_b[ones_sebs]
local Q1_lin = e(rss)
di `t1_linreg'
local abs_t1_linreg = abs(`t1_linreg')
di `abs_t1_linreg'


* PEESE
regress bs_sebs ones_sebs sebs,noc
local peese=_b[ones_sebs]
local b_sq=_b[ones_sebs]
local Q1_sq = e(rss)
di `Q1_sq'
 

* FAT-PET-PEESE

if `abs_t1_linreg' > invt(`M-2', 0.975) {
    local combreg=`b_sq'
	local Q1=`Q1_sq'
	}
else {
    local combreg=`b_lin'
	local Q1=`Q1_lin'
}

* estimation of random effects variance component
local sigh2hat=max(0,`M'*((`Q1'/(`M'-e(df_m)-1))-1)/`wis_sum') 
local sighhat=sqrt(`sigh2hat') 


* Cutoff value for EK
if `combreg'>1.96*`sighhat' {
    local a1=(`combreg'-1.96*`sighhat')*(`combreg'+1.96*`sighhat')/(2*1.96*`combreg')
}
else {
	local a1=0
	}
    
	
	rename bs bs_original
	rename bs_sebs bs
	rename ones_sebs constant
	rename ones pub_bias
	
	
    noisily: display "EK regression: "

if `a1'>`sebs_min' & `a1'<`sebs_max' {
    gen sebs_a1=sebs-`a1' if sebs>`a1'
	replace sebs_a1=0 if sebs<=`a1'
	gen pubbias=sebs_a1/sebs
	noisily regress bs constant pubbias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pubbias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pubbias]
}
else if `a1'<`sebs_min' {
    noisily regress bs constant pub_bias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pub_bias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pub_bias]
}
else if `a1'>`sebs_max' {
    noisily regress bs constant, noc
	local b0_ek=_b[constant]
	local sd0_ek=_se[constant]	
}
noisily: display "EK's mean effect estimate (alpha1) and standard error:"
noisily: di `b0_ek' 
noisily: di `sd0_ek' 
noisily: display "EK's publication bias estimate (delta) and standard error:"
noisily: di `b1_ek' 
noisily: di `sd1_ek' 

}

*AK - SELECTION
*https://maxkasy.github.io/home/metastudy/
* -> Visit https://maxkasy.github.io/home/metastudy/ and upload AK_linguistic_cSE.csv
// Use the following Model parameters:
/*
AK_Selection_model_parameters
Model for the distribution of effects
Student-t

Symmetric p(.) [CHECKED]

Cutoffs for p(.)
1.96

--Output--
estimate
standard error
*/

*Stem: https://github.com/Chishio318/stem-based_method
*in R: 

/*
Open & run R file: ste_linguistic_cSE.R using ste_linguistic_cSE.xlsx

--Output--
estimate
-0.008 0.064
*/

restore
 
//religious_div
//FAT-PET
ivreg2 pcc_win1 altseR_win1 if religious_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {altseR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 Instrum_win1 if religious_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {Instrum_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
xtreg pcc_win1 altseR_win1 if religious_div==1, be // BE
esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 pcc_win1 altseR_win1 [pweight=(1/altseR_win1)] if religious_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {altseR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 altseR_win1 [pweight=(invperstudy)] if religious_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {altseR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)

 
//Bias-corrected effect of diversity on economic growth******
//religious_div
preserve
keep if religious_div==1

*Top10
quietly{
summarize altpcc_prec_win1, detail
local top10bound = r(p90)
summarize pcc_win1 if altpcc_prec_win1 > `top10bound'
summarize altpcc_prec_win1, detail
local top10bound = r(p90)
}
reg pcc_win1 if altpcc_prec_win1 > `top10bound'

***WAAP_1 = the WAAP estimator does not identify any study that would have sufficient power.
*quietly{
*gen ts = pcc_win1/altseR_win1
*summarize pcc_win1 [aweight=1/(altseR_win1^2)] 
*gen waapbound = abs(r(mean))/2.8
*}
*reg ts pcc_prec_win1 if altseR_win1 < waapbound, noconstant
*
//Kinked model (Bom and Rachinger, 2019)
//Code (for stata) available at: https://sites.google.com/site/heikorachinger/codes 
*EK Estimator
quietly {


rename pcc_win1 bs
rename altseR_win1 sebs



gen ones=1
   
sum
local M=r(N)
sum sebs
local sebs_min=r(min)
local sebs_max=r(max)
  
gen sebs2=sebs^2
gen wis=ones/sebs2
gen bs_sebs=bs/sebs
gen ones_sebs=ones/sebs

gen bswis=bs*wis
sum wis
local wis_sum=r(sum)


* FAT-PET
regress bs_sebs ones_sebs ones,noc
local pet=_b[ones_sebs]
local t1_linreg = (_b[ones_sebs]/_se[ones_sebs])
local b_lin=_b[ones_sebs]
local Q1_lin = e(rss)
di `t1_linreg'
local abs_t1_linreg = abs(`t1_linreg')
di `abs_t1_linreg'


* PEESE
regress bs_sebs ones_sebs sebs,noc
local peese=_b[ones_sebs]
local b_sq=_b[ones_sebs]
local Q1_sq = e(rss)
di `Q1_sq'
 

* FAT-PET-PEESE

if `abs_t1_linreg' > invt(`M-2', 0.975) {
    local combreg=`b_sq'
	local Q1=`Q1_sq'
	}
else {
    local combreg=`b_lin'
	local Q1=`Q1_lin'
}

* estimation of random effects variance component
local sigh2hat=max(0,`M'*((`Q1'/(`M'-e(df_m)-1))-1)/`wis_sum') 
local sighhat=sqrt(`sigh2hat') 


* Cutoff value for EK
if `combreg'>1.96*`sighhat' {
    local a1=(`combreg'-1.96*`sighhat')*(`combreg'+1.96*`sighhat')/(2*1.96*`combreg')
}
else {
	local a1=0
	}
    
	
	rename bs bs_original
	rename bs_sebs bs
	rename ones_sebs constant
	rename ones pub_bias
	
	
    noisily: display "EK regression: "

if `a1'>`sebs_min' & `a1'<`sebs_max' {
    gen sebs_a1=sebs-`a1' if sebs>`a1'
	replace sebs_a1=0 if sebs<=`a1'
	gen pubbias=sebs_a1/sebs
	noisily regress bs constant pubbias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pubbias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pubbias]
}
else if `a1'<`sebs_min' {
    noisily regress bs constant pub_bias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pub_bias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pub_bias]
}
else if `a1'>`sebs_max' {
    noisily regress bs constant, noc
	local b0_ek=_b[constant]
	local sd0_ek=_se[constant]	
}
noisily: display "EK's mean effect estimate (alpha1) and standard error:"
noisily: di `b0_ek' 
noisily: di `sd0_ek' 
noisily: display "EK's publication bias estimate (delta) and standard error:"
noisily: di `b1_ek' 
noisily: di `sd1_ek' 

}

*AK - SELECTION
*https://maxkasy.github.io/home/metastudy/
* -> Visit https://maxkasy.github.io/home/metastudy/ and upload AK_religious_cSE.csv
// Use the following Model parameters:
/*
AK_Selection_model_parameters
Model for the distribution of effects
Student-t

Symmetric p(.) [CHECKED]

Cutoffs for p(.)
1.96

--Output--
estimate
standard error
*/

*Stem: https://github.com/Chishio318/stem-based_method
*in R: 

/*
Open & run R file: ste_religious_cSE.R using ste_religious_cSE.xlsx

--Output--
estimate
-0.052 0.056
*/

restore
 
//genetic_div
//FAT-PET
ivreg2 pcc_win1 altseR_win1 if genetic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {altseR_win1} {_cons}, nograph weight(webb)
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 Instrum_win1 if genetic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {Instrum_win1} {_cons}, nograph weight(webb)
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
xtreg pcc_win1 altseR_win1 if genetic_div==1, be // BE
esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 pcc_win1 altseR_win1 [pweight=(1/altseR_win1)] if genetic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {altseR_win1} {_cons}, nograph weight(webb)
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 altseR_win1 [pweight=(invperstudy)] if genetic_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {altseR_win1} {_cons}, nograph weight(webb)
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)

//Bias-corrected effect of diversity on economic growth******
//genetic_div
preserve
keep if genetic_div==1

*Top10
quietly{
summarize altpcc_prec_win1, detail
local top10bound = r(p90)
summarize pcc_win1 if altpcc_prec_win1 > `top10bound'
summarize altpcc_prec_win1, detail
local top10bound = r(p90)
}
reg pcc_win1 if altpcc_prec_win1 > `top10bound'

**WAAP_1 = the WAAP estimator does not identify any study that would have sufficient power.
quietly{
gen ts = pcc_win1/altseR_win1
summarize pcc_win1 [aweight=1/(altseR_win1^2)] 
gen waapbound = abs(r(mean))/2.8
}
reg ts pcc_prec_win1 if altseR_win1 < waapbound, noconstant

//Kinked model (Bom and Rachinger, 2019)
//Code (for stata) available at: https://sites.google.com/site/heikorachinger/codes 
*EK Estimator
quietly {


rename pcc_win1 bs
rename altseR_win1 sebs



gen ones=1
   
sum
local M=r(N)
sum sebs
local sebs_min=r(min)
local sebs_max=r(max)
  
gen sebs2=sebs^2
gen wis=ones/sebs2
gen bs_sebs=bs/sebs
gen ones_sebs=ones/sebs

gen bswis=bs*wis
sum wis
local wis_sum=r(sum)


* FAT-PET
regress bs_sebs ones_sebs ones,noc
local pet=_b[ones_sebs]
local t1_linreg = (_b[ones_sebs]/_se[ones_sebs])
local b_lin=_b[ones_sebs]
local Q1_lin = e(rss)
di `t1_linreg'
local abs_t1_linreg = abs(`t1_linreg')
di `abs_t1_linreg'


* PEESE
regress bs_sebs ones_sebs sebs,noc
local peese=_b[ones_sebs]
local b_sq=_b[ones_sebs]
local Q1_sq = e(rss)
di `Q1_sq'
 

* FAT-PET-PEESE

if `abs_t1_linreg' > invt(`M-2', 0.975) {
    local combreg=`b_sq'
	local Q1=`Q1_sq'
	}
else {
    local combreg=`b_lin'
	local Q1=`Q1_lin'
}

* estimation of random effects variance component
local sigh2hat=max(0,`M'*((`Q1'/(`M'-e(df_m)-1))-1)/`wis_sum') 
local sighhat=sqrt(`sigh2hat') 


* Cutoff value for EK
if `combreg'>1.96*`sighhat' {
    local a1=(`combreg'-1.96*`sighhat')*(`combreg'+1.96*`sighhat')/(2*1.96*`combreg')
}
else {
	local a1=0
	}
    
	
	rename bs bs_original
	rename bs_sebs bs
	rename ones_sebs constant
	rename ones pub_bias
	
	
    noisily: display "EK regression: "

if `a1'>`sebs_min' & `a1'<`sebs_max' {
    gen sebs_a1=sebs-`a1' if sebs>`a1'
	replace sebs_a1=0 if sebs<=`a1'
	gen pubbias=sebs_a1/sebs
	noisily regress bs constant pubbias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pubbias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pubbias]
}
else if `a1'<`sebs_min' {
    noisily regress bs constant pub_bias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pub_bias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pub_bias]
}
else if `a1'>`sebs_max' {
    noisily regress bs constant, noc
	local b0_ek=_b[constant]
	local sd0_ek=_se[constant]	
}
noisily: display "EK's mean effect estimate (alpha1) and standard error:"
noisily: di `b0_ek' 
noisily: di `sd0_ek' 
noisily: display "EK's publication bias estimate (delta) and standard error:"
noisily: di `b1_ek' 
noisily: di `sd1_ek' 

}

*AK - SELECTION
*https://maxkasy.github.io/home/metastudy/
* -> Visit https://maxkasy.github.io/home/metastudy/ and upload AK_genetic_cSE.csv
// Use the following Model parameters:
/*
AK_Selection_model_parameters
Model for the distribution of effects
Student-t

Symmetric p(.) [CHECKED]

Cutoffs for p(.)
1.96

--Output--
estimate
standard error
*/

*Stem: https://github.com/Chishio318/stem-based_method
*in R: 

/*
Open & run R file: ste_genetic_cSE.R using ste_genetic_cSE.xlsx

--Output--
estimate
0.151 0.029
*/

restore

//birthplace_div
//FAT-PET
ivreg2 pcc_win1 altseR_win1 if birthplace_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {altseR_win1} {_cons}, nograph weight(webb)
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 Instrum_win1 if birthplace_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {Instrum_win1} {_cons}, nograph weight(webb)
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
xtreg pcc_win1 altseR_win1 if birthplace_div==1, be // BE
esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 pcc_win1 altseR_win1 [pweight=(1/altseR_win1)] if birthplace_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {altseR_win1} {_cons}, nograph weight(webb)
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 altseR_win1 [pweight=(invperstudy)] if birthplace_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {altseR_win1} {_cons}, nograph weight(webb)
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)

//Bias-corrected effect of diversity on economic growth******
//birthplace_div
preserve
keep if birthplace_div==1

*Top10
quietly{
summarize altpcc_prec_win1, detail
local top10bound = r(p90)
summarize pcc_win1 if altpcc_prec_win1 > `top10bound'
summarize altpcc_prec_win1, detail
local top10bound = r(p90)
}
reg pcc_win1 if altpcc_prec_win1 > `top10bound'

**WAAP_1 = the WAAP estimator does not identify any study that would have sufficient power.
quietly{
gen ts = pcc_win1/altseR_win1
summarize pcc_win1 [aweight=1/(altseR_win1^2)] 
gen waapbound = abs(r(mean))/2.8
}
reg ts pcc_prec_win1 if altseR_win1 < waapbound, noconstant

//Kinked model (Bom and Rachinger, 2019)
//Code (for stata) available at: https://sites.google.com/site/heikorachinger/codes 
*EK Estimator
quietly {


rename pcc_win1 bs
rename altseR_win1 sebs



gen ones=1
   
sum
local M=r(N)
sum sebs
local sebs_min=r(min)
local sebs_max=r(max)
  
gen sebs2=sebs^2
gen wis=ones/sebs2
gen bs_sebs=bs/sebs
gen ones_sebs=ones/sebs

gen bswis=bs*wis
sum wis
local wis_sum=r(sum)


* FAT-PET
regress bs_sebs ones_sebs ones,noc
local pet=_b[ones_sebs]
local t1_linreg = (_b[ones_sebs]/_se[ones_sebs])
local b_lin=_b[ones_sebs]
local Q1_lin = e(rss)
di `t1_linreg'
local abs_t1_linreg = abs(`t1_linreg')
di `abs_t1_linreg'


* PEESE
regress bs_sebs ones_sebs sebs,noc
local peese=_b[ones_sebs]
local b_sq=_b[ones_sebs]
local Q1_sq = e(rss)
di `Q1_sq'
 

* FAT-PET-PEESE

if `abs_t1_linreg' > invt(`M-2', 0.975) {
    local combreg=`b_sq'
	local Q1=`Q1_sq'
	}
else {
    local combreg=`b_lin'
	local Q1=`Q1_lin'
}

* estimation of random effects variance component
local sigh2hat=max(0,`M'*((`Q1'/(`M'-e(df_m)-1))-1)/`wis_sum') 
local sighhat=sqrt(`sigh2hat') 


* Cutoff value for EK
if `combreg'>1.96*`sighhat' {
    local a1=(`combreg'-1.96*`sighhat')*(`combreg'+1.96*`sighhat')/(2*1.96*`combreg')
}
else {
	local a1=0
	}
    
	
	rename bs bs_original
	rename bs_sebs bs
	rename ones_sebs constant
	rename ones pub_bias
	
	
    noisily: display "EK regression: "

if `a1'>`sebs_min' & `a1'<`sebs_max' {
    gen sebs_a1=sebs-`a1' if sebs>`a1'
	replace sebs_a1=0 if sebs<=`a1'
	gen pubbias=sebs_a1/sebs
	noisily regress bs constant pubbias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pubbias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pubbias]
}
else if `a1'<`sebs_min' {
    noisily regress bs constant pub_bias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pub_bias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pub_bias]
}
else if `a1'>`sebs_max' {
    noisily regress bs constant, noc
	local b0_ek=_b[constant]
	local sd0_ek=_se[constant]	
}
noisily: display "EK's mean effect estimate (alpha1) and standard error:"
noisily: di `b0_ek' 
noisily: di `sd0_ek' 
noisily: display "EK's publication bias estimate (delta) and standard error:"
noisily: di `b1_ek' 
noisily: di `sd1_ek' 

}

*AK - SELECTION
*https://maxkasy.github.io/home/metastudy/
* -> Visit https://maxkasy.github.io/home/metastudy/ and upload AK_birthplace_cSE.csv
// Use the following Model parameters:
/*
AK_Selection_model_parameters
Model for the distribution of effects
Student-t

Symmetric p(.) [CHECKED]

Cutoffs for p(.)
1.96

--Output--
estimate
standard error
*/

*Stem: https://github.com/Chishio318/stem-based_method
*in R: 

/*
Open & run R file: ste_birthplace_cSE.R using ste_birthplace_cSE.xlsx

--Output--
estimate
0.064 0.071
*/

restore

//residual category
//FAT-PET
ivreg2 pcc_win1 altseR_win1 if cultural_div==1 | residualcategory_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {altseR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 Instrum_win1 if cultural_div==1 | residualcategory_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {Instrum_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3)) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
xtreg pcc_win1 altseR_win1 if cultural_div==1 | residualcategory_div==1, be // BE
esttab ., cells(b(star fmt(3)) se( fmt(3)))  starl( * 0.10 ** 0.05 *** 0.010) 
ivreg2 pcc_win1 altseR_win1 [pweight=(1/altseR_win1)] if cultural_div==1 | residualcategory_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {altseR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)
ivreg2 pcc_win1 altseR_win1 [pweight=(invperstudy)] if cultural_div==1 | residualcategory_div==1, cl(id)
*SAVE CIs FROM BOOTEST
boottest {altseR_win1} {_cons}, nograph
matrix ll = (r(CI_1)[1,1] , r(CI_2)[1,1])
matrix ul = (r(CI_1)[1,2] , r(CI_2)[1,2])
mat end= (1, 1)
mat colnames ll= `:colnames e(b)'
mat colnames ul= `:colnames e(b)'
mat colnames end= `:colnames e(b)'
*ESTADD MATRICES
estadd matrix myll= ll
estadd matrix myul= ul
estadd matrix end=end
*ESTTAB WITH CUSTOM CIs
 esttab ., cells(b(star fmt(3)) se( fmt(3) par) myll(par("["))&myul&end(par("]"))) substitute (" ]1.000" "]") starl( * 0.10 ** 0.05 *** 0.010)

//Bias-corrected effect of diversity on economic growth******
//residual category
preserve
keep if cultural_div==1 | residualcategory_div==1

*Top10
quietly{
summarize altpcc_prec_win1, detail
local top10bound = r(p90)
summarize pcc_win1 if altpcc_prec_win1 > `top10bound'
summarize altpcc_prec_win1, detail
local top10bound = r(p90)
}
reg pcc_win1 if altpcc_prec_win1 > `top10bound'

***WAAP_1 = the WAAP estimator does not identify any study that would have sufficient power.
*quietly{
*gen ts = pcc_win1/altseR_win1
*summarize pcc_win1 [aweight=1/(altseR_win1^2)] 
*gen waapbound = abs(r(mean))/2.8
*}
*reg ts pcc_prec_win1 if altseR_win1 < waapbound, noconstant
*
//Kinked model (Bom and Rachinger, 2019)
//Code (for stata) available at: https://sites.google.com/site/heikorachinger/codes 
*EK Estimator
quietly {


rename pcc_win1 bs
rename altseR_win1 sebs



gen ones=1
   
sum
local M=r(N)
sum sebs
local sebs_min=r(min)
local sebs_max=r(max)
  
gen sebs2=sebs^2
gen wis=ones/sebs2
gen bs_sebs=bs/sebs
gen ones_sebs=ones/sebs

gen bswis=bs*wis
sum wis
local wis_sum=r(sum)


* FAT-PET
regress bs_sebs ones_sebs ones,noc
local pet=_b[ones_sebs]
local t1_linreg = (_b[ones_sebs]/_se[ones_sebs])
local b_lin=_b[ones_sebs]
local Q1_lin = e(rss)
di `t1_linreg'
local abs_t1_linreg = abs(`t1_linreg')
di `abs_t1_linreg'


* PEESE
regress bs_sebs ones_sebs sebs,noc
local peese=_b[ones_sebs]
local b_sq=_b[ones_sebs]
local Q1_sq = e(rss)
di `Q1_sq'
 

* FAT-PET-PEESE

if `abs_t1_linreg' > invt(`M-2', 0.975) {
    local combreg=`b_sq'
	local Q1=`Q1_sq'
	}
else {
    local combreg=`b_lin'
	local Q1=`Q1_lin'
}

* estimation of random effects variance component
local sigh2hat=max(0,`M'*((`Q1'/(`M'-e(df_m)-1))-1)/`wis_sum') 
local sighhat=sqrt(`sigh2hat') 


* Cutoff value for EK
if `combreg'>1.96*`sighhat' {
    local a1=(`combreg'-1.96*`sighhat')*(`combreg'+1.96*`sighhat')/(2*1.96*`combreg')
}
else {
	local a1=0
	}
    
	
	rename bs bs_original
	rename bs_sebs bs
	rename ones_sebs constant
	rename ones pub_bias
	
	
    noisily: display "EK regression: "

if `a1'>`sebs_min' & `a1'<`sebs_max' {
    gen sebs_a1=sebs-`a1' if sebs>`a1'
	replace sebs_a1=0 if sebs<=`a1'
	gen pubbias=sebs_a1/sebs
	noisily regress bs constant pubbias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pubbias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pubbias]
}
else if `a1'<`sebs_min' {
    noisily regress bs constant pub_bias, noc
	local b0_ek=_b[constant]
	local b1_ek=_b[pub_bias]
	local sd0_ek=_se[constant]
	local sd1_ek=_se[pub_bias]
}
else if `a1'>`sebs_max' {
    noisily regress bs constant, noc
	local b0_ek=_b[constant]
	local sd0_ek=_se[constant]	
}
noisily: display "EK's mean effect estimate (alpha1) and standard error:"
noisily: di `b0_ek' 
noisily: di `sd0_ek' 
noisily: display "EK's publication bias estimate (delta) and standard error:"
noisily: di `b1_ek' 
noisily: di `sd1_ek' 

}

*AK - SELECTION
*https://maxkasy.github.io/home/metastudy/
* -> Visit https://maxkasy.github.io/home/metastudy/ and upload AK_residual_cSE.csv
// Use the following Model parameters:
/*
AK_Selection_model_parameters
Model for the distribution of effects
Student-t

Symmetric p(.) [CHECKED]

Cutoffs for p(.)
1.96

--Output--
estimate
standard error
*/

*Stem: https://github.com/Chishio318/stem-based_method
*in R: 

/*
Open & run R file: ste_birthplace_cSE.R using ste_birthplace_cSE.xlsx

--Output--
estimate
-0.005 0.128
*/

restore
 
 
//Table 4 Variables used in the meta-regression analysis (n=1537)
********Descripton of variables******* 
preserve
keep pcc_win1 seR_win1 growth_real_gdp_per_capita growth_gdp_per_capita real_gdp_per_capita gdp_per_capita ethnic_div linguistic_div religious_div genetic_div birthplace_div residual_div joint crosssection panel single logyears endogeneity ols fixedeffects iv sur other_est_3 income_gdp_per investment human_capital_edu gov_spend open_trade violence health pop_growth democ finance advancedcountriesonly developingcountriesonly mix pub_year journalimpactfactor non_economics_journal econ_journal logcitations






order pcc_win1 seR_win1 growth_real_gdp_per_capita growth_gdp_per_capita real_gdp_per_capita gdp_per_capita ethnic_div linguistic_div religious_div genetic_div birthplace_div residual_div joint crosssection panel single logyears endogeneity ols fixedeffects iv sur other_est_3 income_gdp_per investment human_capital_edu gov_spend open_trade violence health pop_growth democ finance advancedcountriesonly developingcountriesonly mix pub_year journalimpactfactor non_economics_journal econ_journal logcitations
keep pcc_win1 seR_win1 growth_real_gdp_per_capita growth_gdp_per_capita real_gdp_per_capita gdp_per_capita ethnic_div linguistic_div religious_div genetic_div birthplace_div residual_div joint crosssection panel single logyears endogeneity ols fixedeffects iv sur other_est_3 income_gdp_per investment human_capital_edu gov_spend open_trade violence health pop_growth democ finance advancedcountriesonly developingcountriesonly mix pub_year journalimpactfactor non_economics_journal econ_journal logcitations

rename pcc_win1 PCC
rename seR_win1 Standard_error
rename growth_real_gdp_per_capita Growth_real_GDP_pc
rename growth_gdp_per_capita Growth_nomimal_GDP_pc
rename real_gdp_per_capita  Real_GDP_pc
rename gdp_per_capita Nominal_GDP_pc
rename ethnic_div        Ethnic_diversity
rename linguistic_div  Linguistic_diversity
rename religious_div  Religious_diversity
rename genetic_div     Genetic_diversity
rename birthplace_div  Birthplace_diversity
rename residual_div    Residual_category_diversity 
rename joint Joint
rename crosssection     Cross_sectional 
rename panel Panel_data
rename single Single_country
rename logyears Time_span
rename endogeneity Control_for_endogeneity
rename ols OLS
rename fixedeffects Fixed_effects
rename iv IV
rename sur SUR
rename other_est_3 Other_estimator
rename income_gdp_per Initial_income
rename investment Investment
rename human_capital_edu Education
rename gov_spend Government_spending
rename open_trade Trade_openness
rename violence Violence
rename health Health
rename pop_growth Population 
rename democ Democracy
rename finance Financial_development
rename advancedcountriesonly Developed
rename developingcountriesonly Developing
rename mix Mixed 
rename pub_year Publication_year
rename journalimpactfactor Impact_factor
rename non_economics_journal Non_economic_journal 
rename econ_journal Economic_journal
rename logcitations Citations

sum

restore


*****Figure A2 Correlation matrix*****
preserve
keep pcc_win1 seR_win1 growth_real_gdp_per_capita growth_gdp_per_capita real_gdp_per_capita gdp_per_capita ethnic_div linguistic_div religious_div genetic_div birthplace_div residual_div joint crosssection panel single logyears endogeneity ols fixedeffects iv sur other_est_3 income_gdp_per investment human_capital_edu gov_spend open_trade violence health pop_growth democ finance advancedcountriesonly developingcountriesonly mix pub_year journalimpactfactor non_economics_journal econ_journal logcitations

local rhsvars pcc_win1 growth_real_gdp_per_capita growth_gdp_per_capita real_gdp_per_capita gdp_per_capita ethnic_div linguistic_div religious_div genetic_div birthplace_div residual_div joint crosssection panel single logyears endogeneity ols fixedeffects iv sur other_est_3 income_gdp_per investment human_capital_edu gov_spend open_trade violence health pop_growth democ finance advancedcountriesonly developingcountriesonly mix pub_year journalimpactfactor non_economics_journal econ_journal logcitations




order pcc_win1 seR_win1 growth_real_gdp_per_capita growth_gdp_per_capita real_gdp_per_capita gdp_per_capita ethnic_div linguistic_div religious_div genetic_div birthplace_div residual_div joint crosssection panel single logyears endogeneity ols fixedeffects iv sur other_est_3 income_gdp_per investment human_capital_edu gov_spend open_trade violence health pop_growth democ finance advancedcountriesonly developingcountriesonly mix pub_year journalimpactfactor non_economics_journal econ_journal logcitations
keep pcc_win1 seR_win1 growth_real_gdp_per_capita growth_gdp_per_capita real_gdp_per_capita gdp_per_capita ethnic_div linguistic_div religious_div genetic_div birthplace_div residual_div joint crosssection panel single logyears endogeneity ols fixedeffects iv sur other_est_3 income_gdp_per investment human_capital_edu gov_spend open_trade violence health pop_growth democ finance advancedcountriesonly developingcountriesonly mix pub_year journalimpactfactor non_economics_journal econ_journal logcitations

rename seR_win1 Standard_error
rename growth_real_gdp_per_capita Growth_real_GDP_pc
rename growth_gdp_per_capita Growth_nomimal_GDP_pc
rename real_gdp_per_capita  Real_GDP_pc
rename gdp_per_capita Nominal_GDP_pc
rename ethnic_div        Ethnic_diversity
rename linguistic_div  Linguistic_diversity
rename religious_div  Religious_diversity
rename genetic_div     Genetic_diversity
rename birthplace_div  Birthplace_diversity
rename residual_div    Residual_category_diversity 
rename joint Joint
rename crosssection     Cross_sectional 
rename panel Panel_data
rename single Single_country
rename logyears Time_span
rename endogeneity Control_for_endogeneity
rename ols OLS
rename fixedeffects Fixed_effects
rename iv IV
rename sur SUR
rename other_est_3 Other_estimator
rename income_gdp_per Initial_income
rename investment Investment
rename human_capital_edu Education
rename gov_spend Government_spending
rename open_trade Trade_openness
rename violence Violence
rename health Health
rename pop_growth Population 
rename democ Democracy
rename finance Financial_development
rename advancedcountriesonly Developed
rename developingcountriesonly Developing
rename mix Mixed 
rename pub_year Publication_year
rename journalimpactfactor Impact_factor
rename non_economics_journal Non_economic_journal 
rename econ_journal Economic_journal
rename logcitations Citations



drop Growth_nomimal_GDP_pc Residual_category_diversity Cross_sectional Other_estimator Mixed Non_economic_journal 

xi: collin Standard_error Growth_real_GDP_pc Real_GDP_pc Nominal_GDP_pc Ethnic_diversity Linguistic_diversity Religious_diversity Genetic_diversity Birthplace_diversity Joint Panel_data Single_country Time_span Control_for_endogeneity OLS Fixed_effects IV SUR Initial_income Investment Education Government_spending Trade_openness Violence Health Population Democracy Financial_development Developed Developing Publication_year Impact_factor Economic_journal Citations
//maximum vif is: 9.66 for the Real_GDP_pc variable
* => all variance-inflation factors are below 10

save "zCORRPLOT.dta", replace
restore

*In R:
/*
rm(list=ls())
install.packages("data.table")        # Install data.table
library("data.table")
install.packages('RStata')
library("RStata")
library("corrplot")
install.packages("devEMF")
library("devEMF")

library(haven)
A <- read_dta("zCORRPLOT.dta")

A <- A[complete.cases(A), ]

## Correlation matrix
install.packages('corrplot')
library(corrplot)

cormatd<-round(cor(subset(A, select= -pcc_win1)),3)
cormatd[upper.tri(cormatd)] <- NA

#Heatmap
emf(file = "zcorr_plot.emf", emfPlus = FALSE)

cor1<-corrplot(cormatd,method = "color", tl.col = "black", tl.cex=0.7, cl.cex=0.7,
               col = colorRampPalette(c("firebrick1","white","dodgerblue3"))(100), 
               number.digits = 2, number.cex = 0.35, addCoef.col = "black", type= "lower", tl.srt=45)

dev.off()

*/

***Prepare data for R in order to get Table 5 results****
preserve
keep pcc_win1 seR_win1 growth_real_gdp_per_capita growth_gdp_per_capita real_gdp_per_capita gdp_per_capita ethnic_div linguistic_div religious_div genetic_div birthplace_div residual_div joint crosssection panel single logyears endogeneity ols fixedeffects iv sur other_est_3 income_gdp_per investment human_capital_edu gov_spend open_trade violence health pop_growth democ finance advancedcountriesonly developingcountriesonly mix pub_year journalimpactfactor non_economics_journal econ_journal logcitations

local rhsvars pcc_win1 growth_real_gdp_per_capita growth_gdp_per_capita real_gdp_per_capita gdp_per_capita ethnic_div linguistic_div religious_div genetic_div birthplace_div residual_div joint crosssection panel single logyears endogeneity ols fixedeffects iv sur other_est_3 income_gdp_per investment human_capital_edu gov_spend open_trade violence health pop_growth democ finance advancedcountriesonly developingcountriesonly mix pub_year journalimpactfactor non_economics_journal econ_journal logcitations

foreach x of varlist `rhsvars' {
replace `x' = ( `x' / seR_win1 )

}

gen pcc_prec_win1 = 1/seR_win1
order pcc_win1 pcc_prec_win1 growth_real_gdp_per_capita growth_gdp_per_capita real_gdp_per_capita gdp_per_capita ethnic_div linguistic_div religious_div genetic_div birthplace_div residual_div joint crosssection panel single logyears endogeneity ols fixedeffects iv sur other_est_3 income_gdp_per investment human_capital_edu gov_spend open_trade violence health pop_growth democ finance advancedcountriesonly developingcountriesonly mix pub_year journalimpactfactor non_economics_journal econ_journal logcitations
keep pcc_win1 pcc_prec_win1 growth_real_gdp_per_capita growth_gdp_per_capita real_gdp_per_capita gdp_per_capita ethnic_div linguistic_div religious_div genetic_div birthplace_div residual_div joint crosssection panel single logyears endogeneity ols fixedeffects iv sur other_est_3 income_gdp_per investment human_capital_edu gov_spend open_trade violence health pop_growth democ finance advancedcountriesonly developingcountriesonly mix pub_year journalimpactfactor non_economics_journal econ_journal logcitations

rename pcc_prec_win1 Precision
rename growth_real_gdp_per_capita Growth_real_GDP_pc
rename growth_gdp_per_capita Growth_nomimal_GDP_pc
rename real_gdp_per_capita  Real_GDP_pc
rename gdp_per_capita Nominal_GDP_pc
rename ethnic_div        Ethnic_diversity
rename linguistic_div  Linguistic_diversity
rename religious_div  Religious_diversity
rename genetic_div     Genetic_diversity
rename birthplace_div  Birthplace_diversity
rename residual_div    Residual_category_diversity 
rename joint Joint
rename crosssection     Cross_sectional 
rename panel Panel_data
rename single Single_country
rename logyears Time_span
rename endogeneity Control_for_endogeneity
rename ols OLS
rename fixedeffects Fixed_effects
rename iv IV
rename sur SUR
rename other_est_3 Other_estimator
rename income_gdp_per Initial_income
rename investment Investment
rename human_capital_edu Education
rename gov_spend Government_spending
rename open_trade Trade_openness
rename violence Violence
rename health Health
rename pop_growth Population 
rename democ Democracy
rename finance Financial_development
rename advancedcountriesonly Developed
rename developingcountriesonly Developing
rename mix Mixed 
rename pub_year Publication_year
rename journalimpactfactor Impact_factor
rename non_economics_journal Non_economic_journal 
rename econ_journal Economic_journal
rename logcitations Citations

drop Growth_nomimal_GDP_pc Residual_category_diversity Cross_sectional Other_estimator Mixed Non_economic_journal 

save "zTable-PRECISION.dta", replace
restore

******Table 5 - BMA, Figure 3(BMA), Figure 4 (Prior sensitivity), BMA (2) robustness with alternative priors & FMA [Table A8 Results of BMA with alternative priors and results of FMA]**********
//Also, the following command gives: Table A7, Figure A3, Figure A4, Table A9, Figure A5, Figure A6, Table A10, & Figure A7
*In R:
/*
# require(remotes)
# install_version("BMS", version = "0.3.4", repos = "https://cran.r-project.org")
# packageVersion("BMS")

rm(list=ls())
library(BMS)


library(foreign)
burn_       = 1e6
iter_       = 3e6
gprior      = "UIP"
modelprior  = "dilut"
order_PIP   = F
separator   = ","

library(haven)
A <- read_dta("zTable-PRECISION.dta")


A <- A[complete.cases(A), ]

A <- as.data.frame(A)
############################################################
## BMA UIP and dilution 
BMAse  = bms(A, burn=burn_,iter=iter_, g=gprior, mprior=modelprior, nmodel=5000, mcmc="bd", user.int=FALSE)
BMAse_res<-coef(BMAse, order.by.pip =T, exact=T,include.constant = T)
write.csv(BMAse_res,"zBMA_se.csv")
image(BMAse, cex=0.7, xlab="", main="")
summary(BMAse)
plot(BMAse)
pdf("zbma_BMAse.pdf")
image(BMAse, cex=0.7, xlab="", main="", col=c("firebrick1","dodgerblue3"))
plot(BMAse)
dev.off()

#Prior sensitivity ##################
# BRIC-random & HQ-random
BMAse_2  = bms(A, burn=burn_,iter=iter_, g="BRIC", mprior="random", nmodel=5000, mcmc="bd", user.int=FALSE)
BMAse_2res<-coef(BMAse_2, order.by.pip =T, exact=T,include.constant = T)
write.csv(BMAse_2res,"zBMA_se2.csv")
image(BMAse_2, cex=0.7, xlab="", main="")
summary(BMAse_2)
plot(BMAse_2)
pdf("zbma_BMAse2.pdf")
image(BMAse_2, cex=0.7, xlab="", main="", col=c("firebrick1","dodgerblue3"))
plot(BMAse_2)
dev.off()

BMAse_3  = bms(A, burn=burn_,iter=iter_, g="HQ", mprior="random", nmodel=5000, mcmc="bd", user.int=FALSE)
BMAse_3res<-coef(BMAse_3, order.by.pip =T, exact=T,include.constant = T)
write.csv(BMAse_3res,"zBMA_se3.csv")
image(BMAse_3, cex=0.7, xlab="", main="")
summary(BMAse_3)
plot(BMAse_3)
pdf("zbma_BMAse3.pdf")
image(BMAse_3, cex=0.7, xlab="", main="", col=c("firebrick1","dodgerblue3"))
plot(BMAse_3)
dev.off()

par(mfrow = c(1, 1))
par(mar = c(4, 2.5, 2, 2))
pdf("zBMAse-sensitivity.pdf")
plotComp("UIP and Dilution"=BMAse,"BRIC and Random"=BMAse_2,"HQ and Random"=BMAse_3, add.grid=F,cex.xaxis=0.7)
dev.off()


#################################################################################################################
#########Robustness:FMA#########
library(foreign)
library(xtable)
library(LowRankQP)



library(readstata13)



mydata <- read.dta13("zTable-PRECISION.dta")

mydata <-na.omit(mydata)

x.data <- mydata[,-1]

#adding constant
const_<-c(1)
x.data <-cbind(const_,x.data)


x <- sapply(1:ncol(x.data),function(i){x.data[,i]/max(x.data[,i])})   
scale.vector <- as.matrix(sapply(1:ncol(x.data),function(i){max(x.data[,i])}))        
Y <- as.matrix(mydata[,1])
output.colnames <- colnames(x.data)
full.fit <- lm(Y~x-1)
beta.full <- as.matrix(coef(full.fit))
M <- k <- ncol(x)
n <- nrow(x)
beta <- matrix(0,k,M)
e <- matrix(0,n,M)
K_vector <- matrix(c(1:M))
var.matrix <- matrix(0,k,M)
bias.sq <- matrix(0,k,M)             


# MMA Estimator using orthogonalization 
for(i in 1:M)
{
  X <- as.matrix(x[,1:i])
  ortho <- eigen(t(X)%*%X)
  Q <- ortho$vectors ; lambda <- ortho$values 
  x.tilda <- X%*%Q%*%(diag(lambda^-0.5,i,i))
  beta.star <- t(x.tilda)%*%Y
  beta.hat <- Q%*%diag(lambda^-0.5,i,i)%*%beta.star
  beta[1:i,i] <- beta.hat
  e[,i] <- Y-x.tilda%*%as.matrix(beta.star)
  bias.sq[,i] <- (beta[,i]-beta.full)^2
  var.matrix.star <- diag(as.numeric(((t(e[,i])%*%e[,i])/(n-i))),i,i)
  var.matrix.hat <- var.matrix.star%*%(Q%*%diag(lambda^-1,i,i)%*%t(Q))
  var.matrix[1:i,i] <- diag(var.matrix.hat)
  var.matrix[,i] <- var.matrix[,i]+ bias.sq[,i]
} # End loop over i

e_k <- e[,M]
sigma_hat <- as.numeric((t(e_k)%*%e_k)/(n-M))
G <- t(e)%*%e
a <- ((sigma_hat)^2)*K_vector
A <- matrix(1,1,M)
b <- matrix(1,1,1)
u <- matrix(1,M,1)
optim <- LowRankQP(Vmat=G,dvec=a,Amat=A,bvec=b,uvec=u,method="LU",verbose=TRUE)
weights <- as.matrix(optim$alpha)
beta.scaled <- beta%*%weights
final.beta <- beta.scaled/scale.vector
std.scaled <- sqrt(var.matrix)%*%weights
final.std <- std.scaled/scale.vector
results.reduced <- as.matrix(cbind(final.beta,final.std))
rownames(results.reduced) <- output.colnames; colnames(results.reduced) <- c("Coefficient", "Sd. Err")
#MMA.fls <- round(results.reduced,4)[-1,]
MMA.fls <- round(results.reduced,4)
list(MMA.fls)


MMA.fls <- data.frame(MMA.fls)
t <- as.data.frame(MMA.fls$Coefficient/MMA.fls$Sd..Err)
MMA.fls$pv <-round( (1-apply(as.data.frame(apply(t,1,abs)), 1, pnorm))*2,3)
MMA.fls$names <- rownames(MMA.fls)
names <- c(colnames(mydata))
names <- c(names,"const_")
MMA.fls <- MMA.fls[match(names, MMA.fls$names),]
MMA.fls$names <- NULL
MMA.fls
write.csv(MMA.fls,"zFMA.csv")

*/

******Table 5 - WLS (middle panel)**********
preserve
keep id pcc_win1 seR_win1 growth_real_gdp_per_capita growth_gdp_per_capita real_gdp_per_capita gdp_per_capita ethnic_div linguistic_div religious_div genetic_div birthplace_div residual_div joint crosssection panel single logyears endogeneity ols fixedeffects iv sur other_est_3 income_gdp_per investment human_capital_edu gov_spend open_trade violence health pop_growth democ finance advancedcountriesonly developingcountriesonly mix pub_year journalimpactfactor non_economics_journal econ_journal logcitations

local rhsvars pcc_win1 growth_real_gdp_per_capita growth_gdp_per_capita real_gdp_per_capita gdp_per_capita ethnic_div linguistic_div religious_div genetic_div birthplace_div residual_div joint crosssection panel single logyears endogeneity ols fixedeffects iv sur other_est_3 income_gdp_per investment human_capital_edu gov_spend open_trade violence health pop_growth democ finance advancedcountriesonly developingcountriesonly mix pub_year journalimpactfactor non_economics_journal econ_journal logcitations

foreach x of varlist `rhsvars' {
				replace `x' = ( `x' / seR_win1 )
					
}

gen pcc_prec_win1 = 1/seR_win1
order pcc_win1 pcc_prec_win1 growth_real_gdp_per_capita growth_gdp_per_capita real_gdp_per_capita gdp_per_capita ethnic_div linguistic_div religious_div genetic_div birthplace_div residual_div joint crosssection panel single logyears endogeneity ols fixedeffects iv sur other_est_3 income_gdp_per investment human_capital_edu gov_spend open_trade violence health pop_growth democ finance advancedcountriesonly developingcountriesonly mix pub_year journalimpactfactor non_economics_journal econ_journal logcitations
keep id pcc_win1 pcc_prec_win1 growth_real_gdp_per_capita growth_gdp_per_capita real_gdp_per_capita gdp_per_capita ethnic_div linguistic_div religious_div genetic_div birthplace_div residual_div joint crosssection panel single logyears endogeneity ols fixedeffects iv sur other_est_3 income_gdp_per investment human_capital_edu gov_spend open_trade violence health pop_growth democ finance advancedcountriesonly developingcountriesonly mix pub_year journalimpactfactor non_economics_journal econ_journal logcitations


rename pcc_prec_win1 Precision
rename growth_real_gdp_per_capita Growth_real_GDP_pc
rename growth_gdp_per_capita Growth_nomimal_GDP_pc
rename real_gdp_per_capita  Real_GDP_pc
rename gdp_per_capita Nominal_GDP_pc
rename ethnic_div        Ethnic_diversity
rename linguistic_div  Linguistic_diversity
rename religious_div  Religious_diversity
rename genetic_div     Genetic_diversity
rename birthplace_div  Birthplace_diversity
rename residual_div    Residual_category_diversity 
rename joint Joint
rename crosssection     Cross_sectional 
rename panel Panel_data
rename single Single_country
rename logyears Time_span
rename endogeneity Control_for_endogeneity
rename ols OLS
rename fixedeffects Fixed_effects
rename iv IV
rename sur SUR
rename other_est_3 Other_estimator
rename income_gdp_per Initial_income
rename investment Investment
rename human_capital_edu Education
rename gov_spend Government_spending
rename open_trade Trade_openness
rename violence Violence
rename health Health
rename pop_growth Population 
rename democ Democracy
rename finance Financial_development
rename advancedcountriesonly Developed
rename developingcountriesonly Developing
rename mix Mixed 
rename pub_year Publication_year
rename journalimpactfactor Impact_factor
rename non_economics_journal Non_economic_journal 
rename econ_journal Economic_journal
rename logcitations Citations

//WLS - heterogeneity
reg pcc_win1 Precision Growth_real_GDP_pc Nominal_GDP_pc Ethnic_diversity Linguistic_diversity Religious_diversity Genetic_diversity Birthplace_diversity Joint Panel_data Single_country Time_span Fixed_effects Initial_income Government_spending Violence Health Population Developing Publication_year Impact_factor Economic_journal, vce(cluster id)
restore

******Table 5 (right-hand panel) - WALS**********
preserve
keep id pcc_win1 seR_win1 growth_real_gdp_per_capita growth_gdp_per_capita real_gdp_per_capita gdp_per_capita ethnic_div linguistic_div religious_div genetic_div birthplace_div residual_div joint crosssection panel single logyears endogeneity ols fixedeffects iv sur other_est_3 income_gdp_per investment human_capital_edu gov_spend open_trade violence health pop_growth democ finance advancedcountriesonly developingcountriesonly mix pub_year journalimpactfactor non_economics_journal econ_journal logcitations

local rhsvars pcc_win1 growth_real_gdp_per_capita growth_gdp_per_capita real_gdp_per_capita gdp_per_capita ethnic_div linguistic_div religious_div genetic_div birthplace_div residual_div joint crosssection panel single logyears endogeneity ols fixedeffects iv sur other_est_3 income_gdp_per investment human_capital_edu gov_spend open_trade violence health pop_growth democ finance advancedcountriesonly developingcountriesonly mix pub_year journalimpactfactor non_economics_journal econ_journal logcitations

foreach x of varlist `rhsvars' {
				replace `x' = ( `x' / seR_win1 )
					
}

gen pcc_prec_win1 = 1/seR_win1
order pcc_win1 pcc_prec_win1 growth_real_gdp_per_capita growth_gdp_per_capita real_gdp_per_capita gdp_per_capita ethnic_div linguistic_div religious_div genetic_div birthplace_div residual_div joint crosssection panel single logyears endogeneity ols fixedeffects iv sur other_est_3 income_gdp_per investment human_capital_edu gov_spend open_trade violence health pop_growth democ finance advancedcountriesonly developingcountriesonly mix pub_year journalimpactfactor non_economics_journal econ_journal logcitations
keep id pcc_win1 pcc_prec_win1 growth_real_gdp_per_capita growth_gdp_per_capita real_gdp_per_capita gdp_per_capita ethnic_div linguistic_div religious_div genetic_div birthplace_div residual_div joint crosssection panel single logyears endogeneity ols fixedeffects iv sur other_est_3 income_gdp_per investment human_capital_edu gov_spend open_trade violence health pop_growth democ finance advancedcountriesonly developingcountriesonly mix pub_year journalimpactfactor non_economics_journal econ_journal logcitations

rename pcc_prec_win1 Precision
rename growth_real_gdp_per_capita Growth_real_GDP_pc
rename growth_gdp_per_capita Growth_nomimal_GDP_pc
rename real_gdp_per_capita  Real_GDP_pc
rename gdp_per_capita Nominal_GDP_pc
rename ethnic_div        Ethnic_diversity
rename linguistic_div  Linguistic_diversity
rename religious_div  Religious_diversity
rename genetic_div     Genetic_diversity
rename birthplace_div  Birthplace_diversity
rename residual_div    Residual_category_diversity 
rename joint Joint
rename crosssection     Cross_sectional 
rename panel Panel_data
rename single Single_country
rename logyears Time_span
rename endogeneity Control_for_endogeneity
rename ols OLS
rename fixedeffects Fixed_effects
rename iv IV
rename sur SUR
rename other_est_3 Other_estimator
rename income_gdp_per Initial_income
rename investment Investment
rename human_capital_edu Education
rename gov_spend Government_spending
rename open_trade Trade_openness
rename violence Violence
rename health Health
rename pop_growth Population 
rename democ Democracy
rename finance Financial_development
rename advancedcountriesonly Developed
rename developingcountriesonly Developing
rename mix Mixed 
rename pub_year Publication_year
rename journalimpactfactor Impact_factor
rename non_economics_journal Non_economic_journal 
rename econ_journal Economic_journal
rename logcitations Citations


//General: all variables
eststo clear
eststo: wals pcc_win1 Precision , auxiliary(Growth_real_GDP_pc Real_GDP_pc Nominal_GDP_pc Ethnic_diversity Linguistic_diversity Religious_diversity Genetic_diversity Birthplace_diversity Joint Panel_data Single_country Time_span Control_for_endogeneity OLS Fixed_effects IV SUR Initial_income Investment Education Government_spending Trade_openness Violence Health Population Democracy Financial_development Developed Developing Publication_year Impact_factor Economic_journal Citations)

esttab, wide b(3)  t(3)  nogaps nostar
esttab, wide b(3)  se(3)  nogaps nostar

//https://onlinelibrary.wiley.com/doi/full/10.1111/joes.12489
//https://onlinelibrary.wiley.com/doi/10.1111/joes.12605
//specific: moderators from General with |t-value|>1
wals pcc_win1 Precision , auxiliary(Growth_real_GDP_pc Real_GDP_pc Nominal_GDP_pc Ethnic_diversity Linguistic_diversity Religious_diversity Genetic_diversity Birthplace_diversity Joint Panel_data Single_country Time_span Fixed_effects IV SUR Initial_income Investment Education Government_spending Violence Health Population Democracy Developing Publication_year Impact_factor Economic_journal)

eststo clear
restore


*******************Table 6: Best research practice*************************************
preserve
rename growth_real_gdp_per_capita Growth_real_GDP_pc
rename growth_gdp_per_capita Growth_nomimal_GDP_pc
rename real_gdp_per_capita  Real_GDP_pc
rename gdp_per_capita Nominal_GDP_pc
rename ethnic_div        Ethnic_diversity
rename linguistic_div  Linguistic_diversity
rename religious_div  Religious_diversity
rename genetic_div     Genetic_diversity
rename birthplace_div  Birthplace_diversity
rename residual_div    Residual_category_diversity 
rename joint Joint
rename crosssection     Cross_sectional 
rename panel Panel_data
rename single Single_country
rename logyears Time_span
rename endogeneity Control_for_endogeneity
rename ols OLS
rename fixedeffects Fixed_effects
rename iv IV
rename sur SUR
rename other_est_3 Other_estimator
rename income_gdp_per Initial_income
rename investment Investment
rename human_capital_edu Education
rename gov_spend Government_spending
rename open_trade Trade_openness
rename violence Violence
rename health Health
rename pop_growth Population 
rename democ Democracy
rename finance Financial_development
rename advancedcountriesonly Developed
rename developingcountriesonly Developing
rename mix Mixed 
rename pub_year Publication_year
rename journalimpactfactor Impact_factor
rename non_economics_journal Non_economic_journal 
rename econ_journal Economic_journal
rename logcitations Citations

local variables Growth_real_GDP_pc Real_GDP_pc Nominal_GDP_pc Ethnic_diversity Linguistic_diversity Religious_diversity Genetic_diversity Birthplace_diversity Joint Panel_data Single_country Time_span Control_for_endogeneity OLS Fixed_effects IV SUR Initial_income Investment Education Government_spending Trade_openness Violence Health Population Democracy Financial_development Developed Developing Publication_year Impact_factor Economic_journal Citations

foreach x of varlist `variables' {

sum  `x' [aweight=1/seR_win1]
local m`x' = r(mean)
local min`x' =r(min)
local max`x' =r(max)
}


//BEST PRACTISE
qui ivreg2 pcc_win1 seR_win1  Growth_real_GDP_pc Real_GDP_pc Nominal_GDP_pc Ethnic_diversity Linguistic_diversity Religious_diversity Genetic_diversity Birthplace_diversity Joint Panel_data Single_country Time_span Control_for_endogeneity OLS Fixed_effects IV SUR Initial_income Investment Education Government_spending Trade_openness Violence Health Population Democracy Financial_development Developed Developing Publication_year Impact_factor Economic_journal Citations [pweight=1/seR_win1], cluster(id2)


//BP1 - Ethnic diversity BASELINE
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*1 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP1 - Ethnic diversity Panel
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*1 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*1 + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP1 - Ethnic diversity Cross-sectional + (Time span == minimum) 
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*1 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*0 + Single_country*`mSingle_country' + Time_span*`minTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP1 - Ethnic diversity Developed
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*1 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*1 + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP1 - Ethnic diversity Developing
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*1 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*0 + Developing*1 + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP1 - Ethnic diversity Growth_real_GDP_pc
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*1 + Real_GDP_pc*0 + Nominal_GDP_pc*0 + Ethnic_diversity*1 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP1 - Ethnic diversity Single & developed country
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*1 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*1 + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*1 + Developing*0 + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP1 - Ethnic diversity Single & developing country
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*1 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*1 + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*0 + Developing*1 + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP1 - Ethnic diversity No joint
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*1 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*0 + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'



//BP2 - Linguistic diversity BASELINE
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*1 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP2 - Linguistic diversity Panel
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*1 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*1 + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP2 - Linguistic diversity Cross-sectional + (Time span == minimum) 
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*1 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*0 + Single_country*`mSingle_country' + Time_span*`minTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP2 - Linguistic diversity Developed
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*1 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*1 + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP2 - Linguistic diversity Developing
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*1 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*0 + Developing*1 + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP2 - Linguistic diversity Growth_real_GDP_pc
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*1 + Real_GDP_pc*0 + Nominal_GDP_pc*0 + Ethnic_diversity*0 + Linguistic_diversity*1 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP2 - Linguistic diversity Single & developed country
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*1 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*1 + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*1 + Developing*0 + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP2 - Linguistic diversity Single & developing country
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*1 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*1 + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*0 + Developing*1 + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP2 - Linguistic diversity No joint
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*1 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*0 + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'



//BP3 - Religious diversity BASELINE
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*1 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP3 - Religious diversity Panel
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*1 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*1 + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP3 - Religious diversity Cross-sectional + (Time span == minimum) 
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*1 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*0 + Single_country*`mSingle_country' + Time_span*`minTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP3 - Religious diversity Developed
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*1 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*1 + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP3 - Religious diversity Developing
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*1 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*0 + Developing*1 + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP3 - Religious diversity Growth_real_GDP_pc
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*1 + Real_GDP_pc*0 + Nominal_GDP_pc*0 + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*1 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP3 - Religious diversity Single & developed country
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*1 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*1 + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*1 + Developing*0 + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP3 - Religious diversity Single & developing country
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*1 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*1 + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*0 + Developing*1 + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP3 - Religious diversity No joint
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*1 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*0 + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'



//BP4 - Genetic diversity BASELINE
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*1 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP4 - Genetic diversity Panel
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*1 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*1 + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP4 - Genetic diversity Cross-sectional + (Time span == minimum) 
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*1 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*0 + Single_country*`mSingle_country' + Time_span*`minTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP4 - Genetic diversity Developed
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*1 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*1 + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP4 - Genetic diversity Developing
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*1 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*0 + Developing*1 + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP4 - Genetic diversity Growth_real_GDP_pc
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*1 + Real_GDP_pc*0 + Nominal_GDP_pc*0 + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*1 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP4 - Genetic diversity Single & developed country
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*1 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*1 + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*1 + Developing*0 + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP4 - Genetic diversity Single & developing country
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*1 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*1 + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*0 + Developing*1 + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP4 - Genetic diversity No joint
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*1 + Birthplace_diversity*0 + Joint*0 + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'



//BP5 - Birthplace diversity BASELINE
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*1 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP5 - Birthplace diversity Panel
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*1 + Joint*`mJoint' + Panel_data*1 + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP5 - Birthplace diversity Cross-sectional + (Time span == minimum) 
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*1 + Joint*`mJoint' + Panel_data*0 + Single_country*`mSingle_country' + Time_span*`minTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP5 - Birthplace diversity Developed
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*1 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*1 + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP5 - Birthplace diversity Developing
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*1 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*0 + Developing*1 + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP5 - Birthplace diversity Growth_real_GDP_pc
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*1 + Real_GDP_pc*0 + Nominal_GDP_pc*0 + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*1 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP5 - Birthplace diversity Single & developed country
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*1 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*1 + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*1 + Developing*0 + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP5 - Birthplace diversity Single & developing country
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*1 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*1 + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*0 + Developing*1 + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP5 - Birthplace diversity No joint
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*1 + Joint*0 + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'


//BP6 - Residual category diversity BASELINE
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP6 - Residual category diversity Panel
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*1 + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP6 - Residual category diversity Cross-sectional + (Time span == minimum) 
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*0 + Single_country*`mSingle_country' + Time_span*`minTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP6 - Residual category diversity Developed
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*1 + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP6 - Residual category diversity Developing
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*0 + Developing*1 + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP6 - Residual category diversity Growth_real_GDP_pc
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*1 + Real_GDP_pc*0 + Nominal_GDP_pc*0 + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP6 - Residual category diversity Single & developed country
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*1 + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*1 + Developing*0 + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP6 - Residual category diversity Single & developing country
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*`mJoint' + Panel_data*`mPanel_data' + Single_country*1 + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*0 + Developing*1 + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

//BP6 - Residual category diversity No joint
lincom _cons + seR_win1*0 + Growth_real_GDP_pc*`mGrowth_real_GDP_pc' + Real_GDP_pc*`mReal_GDP_pc' + Nominal_GDP_pc*`mNominal_GDP_pc' + Ethnic_diversity*0 + Linguistic_diversity*0 + Religious_diversity*0 + Genetic_diversity*0 + Birthplace_diversity*0 + Joint*0 + Panel_data*`mPanel_data' + Single_country*`mSingle_country' + Time_span*`mTime_span' + Control_for_endogeneity*1 + OLS*0 + Fixed_effects*0 + IV*1 + SUR*0 + Initial_income*1 + Investment*1 + Education*1 + Government_spending*1 + Trade_openness*1 + Violence*1 + Health*1 + Population*1 + Democracy*1 + Financial_development*1 + Developed*`mDeveloped' + Developing*`mDeveloping' + Publication_year*`mPublication_year' + Impact_factor*`maxImpact_factor' + Economic_journal*1 + Citations*`maxCitations'

restore
